Consider a kind m : * -> *
and assume that I know how to define (let's say) a monadic structure on m
, but only when its arguments satisfy some constraint C
, for instance Eq
. In other words, I have a function
(>>=) :: => m a -> (a -> m b) -> b`
that satisfies the monad laws, but in order to define it I would need to have (Eq a, Eq b)
.
Unfortunately, the definition
instance Monad m where
(>>=) :: (Eq a, Eq b) => m a -> (a -> m b) -> b
is considered illegal. This is a bummer because I only plan on using m
on Eq
-types, and this condition could easily be statically checked.
Is there some way to get around this? Either conceptually, or practically?
Many thanks