After getting help on an error where I used =>
rather than ->
, I'm trying to implement distrib
:
distrib :: (Monad m, Monad n) => n (m a) -> m (n a)
distrib x = do xx <- x
return xx
But, this does not work given the compile-time error:
Expected type: m (m a)
Actual type: n (m a)
I realized that using do
notation won't work since, when calling xx <- x
, the expected return type (of the do
block) is x
, i.e. n (m a)
- that's not what I want.
Please give me a hint on how to implement this function.