There's a Monad I'm trying to define, lets call it MyData
.
Inside MyData
there's some IO actions going on, there's a function runMyMonad
that executes them.
Naturally I have to define >>=
, with the following type signature:
instance Monad MyData ...
(>>=) :: MyData a -> (a -> MyData b) -> MyData b
I'd particularly like to define a Monad because I'd like users to be able to use "do" notation.
The thing is, to actually do what I want to do, I need to know some information that entirely depends on the type of b
. Like the following:
myfunc (undefined :: b)
I could create a type class like so, but then there's a problem, my Monad no longer works because Monad requires a
and b
to be unrestricted.
I could create MyData
like the following:
data MyData a where
MyData :: (MyTypeClass a) => a -> a -> MyData a
Or something similar. That way when I pattern match on it, I get the typeclass for free. But I can only see this working on the first argument of >>=
, as the second is wrapped up in a function.
So this is what I want to do:
a) Be able to apply a function that depends only on the type b
in >>=
.
b) Be able to use do
notation.
c) Not affect other uses of Monad
.
Any ideas will be appreciated.