Bella James
Bella James

Reputation: 47

Haskell instance show char without single quotes

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

Answers (1)

radrow
radrow

Reputation: 7159

Use the fact that String is an alias for [Char]:

instance Show Expr where
  show (Var x) = [x]

Upvotes: 3

Related Questions