“分类"在Haskell表演吗? [英] "Subclassing" show in Haskell?
本文介绍了“分类"在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表演吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文