Mik*_* S. 2 haskell functional-programming typeclass
我有一个非常简单的data,我想使用ShowTypeclass给它一个很好的输出.
data Fruit = Apple | Orange Int
instance Show Fruit
where
show Apple = "Hey Apple"
show Orange a = "X number of Orange"
Run Code Online (Sandbox Code Playgroud)
这给出了以下错误,但我不知道如何解决它:
Equations for `show' have different numbers of arguments
Run Code Online (Sandbox Code Playgroud)
你刚忘了一些parens :)
instance Show Fruit where
show Apple = "Hey Apple"
show (Orange a) = show a ++ " number of Orange"
Run Code Online (Sandbox Code Playgroud)
Orange a需要parens的模式可以消除歧义,例如Apple a我们真正有两个参数的地方.
| 归档时间: |
|
| 查看次数: |
86 次 |
| 最近记录: |