我有这个类型定义:
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)
我不想添加Show
for (Int->Int->Int)
,我只想打印字符串。
感谢帮助!
编辑:
为了将来参考,固定版本是:
data Operace = Op (Int->Int->Int) String (Int->Int->Int)
instance Show Operace where
show (Op _ str _) = str