Reputation: 47
This is what I tried so far
data Expr = Var Char
instance Show Expr where
show (Var x) = show x
Variables should be printed as their single-character name. e.g. (Var 'x') prints as x
This is the output i get:
*Test> (Var 'x')
'x'
Can someone help me with this.
Upvotes: 2
Views: 171
Reputation: 7159
Use the fact that String
is an alias for [Char]
:
instance Show Expr where
show (Var x) = [x]
Upvotes: 3