【发布时间】:2011-05-21 13:38:56
【问题描述】:
我有这个类型定义:
data Operace = Op (Int->Int->Int) String (Int->Int->Int) deriving Show
我想将此类型打印到交互式外壳 (GHCi) 中。应该打印的只是String 字段。
我试过了:
instance Show Operace where
show (Op op str inv) = show str
但我还是不断地得到
No instance for (Show (Int -> Int -> Int))
arising from the 'deriving' clause of a data type declaration
Possible fix:
add an instance declaration for (Show (Int -> Int -> Int))
or use a standalone 'deriving instance' declaration,
so you can specify the instance context yourself
When deriving the instance for (Show Operace)
我不想为(Int->Int->Int) 添加Show,我只想打印字符串。
感谢您的帮助!
编辑:
供以后参考,固定版本为:
data Operace = Op (Int->Int->Int) String (Int->Int->Int)
instance Show Operace where
show (Op _ str _) = str
【问题讨论】:
标签: haskell show typeclass ghci