“分类"在Haskell表演吗?

编程入门 行业动态 更新时间:2024-10-28 04:19:12
本文介绍了“分类"在Haskell表演吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

让我说以下内容:

data Greek = Alpha | Beta | Gamma | Phi deriving Show

我想使用除Beta以外的所有项目的默认显示,我想说两个".

I want to use the default showing of all items except Beta, which I want to say "two".

我可以这样做吗?

推荐答案

deriving Show使用标准实例化机制(仅返回定义).如果您需要任何特殊的东西,则必须手动实例化它:

deriving Show uses the standard instantiation mechanism (simply returning the definition). If you want any special things, you will have to instantiate it manually:

data Greek = Alpha | Beta | Gamma | Phi instance Show Greek where show Alpha = "Alpha" show Beta = "2" show Gamma = "Gamma" show Phi = "Phi"

更多推荐

“分类"在Haskell表演吗?

本文发布于:2023-11-30 12:25:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:quot   Haskell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!