Why does `hoist` constrain the type parameter of this monad?
I have some function that composes two monads:
comp :: Monad m => m a -> m b -> m b
And two instances of such monads, where on is "inside" an Mfunctor,
ms :: Monad m => m String
ms = undefined
tma :: (Monad m, MFunctor t) => t m a
tma = undefined
Now if I try to compose ms with tma:
tmas = hoist (\ma -> comp ma ms) tma
I am getting this error:
Could not deduce (a ~ [Char])
from the context (Monad m, MFunctor t)
bound by the inferred type of
comp :: (Monad m, MFunctor t) => t m b
at Coroutine.hs:607:1-40
`a' is a rigid type variable bound by
a type expected by the context: m a -> m a at Coroutine.hs:607:8
Expected type: m a
Actual type: m String
which states that a in ms has to be of arbitrary type: ms :: Monad m => m a.
Why is this and is there a way to compose tma with monads of specific
parameters.
I can see that signature of hoist is:
hoist :: (Monad m, MFunctor t) => (forall a. m a -> n a) -> t m b -> t n b
but cannot picture how forall is affecting what I am trying to do, if it
has any effect.
No comments:
Post a Comment