I'm trying to make a pair an instance of Printable
, but I can't figure out the correct syntax.
My Printable is this:
class Printable a where
toString :: a -> [Char]
instance Printable Bool where
toString True = "true"
toString False = "false"
instance Printable () where
toString () = "unit type"
and my instance for pairs is this:
instance Printable ( a, b ) where
toString (a,b) = "(" ++ toString a ++ ","++ toString b ++ ")"
which, upon compiling, gives me a No instance for (Printable a) arising from a use of ‘toString’
.
What am I doing wrong?