本文介绍了“分类"在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表演吗?
发布评论