相关疑难解决方法(0)

Haskell:为自定义类型导出显示

我有这种类型的定义:

data Operace = Op (Int->Int->Int) String (Int->Int->Int) deriving Show
Run Code Online (Sandbox Code Playgroud)

我想将此类型打印到交互式shell(GHCi)中.所有应该打印的是该String领域.

我试过这个:

instance Show Operace where
    show (Op op str inv) = show str
Run Code Online (Sandbox Code Playgroud)

但我仍然坚持下去

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 …
Run Code Online (Sandbox Code Playgroud)

haskell show typeclass ghci

30
推荐指数
2
解决办法
2万
查看次数

标签 统计

ghci ×1

haskell ×1

show ×1

typeclass ×1