Haskell: Deriving Show for custom type

前端 未结 2 734
傲寒
傲寒 2021-02-05 02:12

I have this type definition:

data Operace = Op (Int->Int->Int) String (Int->Int->Int) deriving Show

I want to print this type into

相关标签:
2条回答
  • 2021-02-05 02:48

    The instance declaration you made is the correct way to go. It seems you forgot to remove that faulty deriving clause from the original data declaration.

    data Operace = Op (Int->Int->Int) String (Int->Int->Int)
    
    instance Show Operace where
       show (Op op str inv) = show str
    
    0 讨论(0)
  • 2021-02-05 02:54

    You can derive Show, just import Text.Show.Functions first.

    0 讨论(0)
提交回复
热议问题