Haskell : Show instance Ambiguity

前端 未结 1 558
悲哀的现实
悲哀的现实 2021-01-25 00:46

I am trying to write a show instance to display well formed formula but after miming whole syntax I am still facing the same error as below.

Hugs> :load \"C:         


        
1条回答
  •  生来不讨喜
    2021-01-25 01:43

    In haskell, whitespace is important. You need to indent the show's that belong to your instance of Show.

    instance Show Wff where
       show (VAR x)     = show x
       show (NEG x)     = "~" ++ show x
       show (AND x y)   = "(" ++ show x ++ "^" ++ show y ++ ")"
       show (OR x y)    = "(" ++ show x ++ "v" ++ show y ++ ")"
       show (IMPL x y)  = "(" ++ show x ++ "-->" ++ show y ++ ")"
    

    Also, you do not need parenthesis to pass the parameters to show. show(x) should be show x.


    If you are learning haskell I recommend these exceptional resources:

    • Learn You a Haskell For Great Good
    • Real World Haskell

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