The codes looks like this:
class MyAnd a where
myAnd :: (Show a) => a -> a -> String
x `myAnd` y = (show x) ++ " and " ++ (show y)
data TrafficLight = Red | Yellow | Green deriving(Show, MyAnd)
Here MyAnd
is a type class which has a function myAnd
, I thought it is generic and the only constraint is the a
has to has an instance of Show
class..
In the TrafficLight
type, it already derived from Show
type class. However, when I compiled the codes, the compiler complains
Can't make a derived instance of ‘MyAnd TrafficLight’:
‘MyAnd’ is not a derivable class
In the data declaration for ‘TrafficLight’
Failed, modules loaded: none.
Does anyone have ideas about this?