Given the Free Monad
:
data Free f a = Var a
| Node (f (Free f a))
I tried to define an Eq
instance for it:
instance (Functor f, Eq (f a)) => Eq (Free f a) where
(==) (Var x) (Var y) = x == y
(==) (Node fu1) (Node fu2) = fu1 == fu2
(==) _ _ = False
But that fails to compile:
FreeMonad.hs:17:10:
Non type-variable argument in the constraint: Eq (f a)
(Use FlexibleContexts to permit this)
In the context: (Functor f, Eq (f a))
While checking an instance declaration
In the instance declaration for ‘Eq (Free f a)’
Failed, modules loaded: none.
Specifying a constraint/pre-condition of (Functor f, Eq (f a))
seems odd to me (at least I don't think that I've seen it as a beginner before).
How can I define an Eq
instance for Free f a
?