[Haskell-cafe] Problems with nested Monads
ekmett at gmail.com
Fri Jul 10 15:09:48 EDT 2009
The problem you have is that monad composition isn't defined in general. You
would need some form of distributive law either for your monads in general,
or for your particular monads wrapped around this particular kind of value.
What I would look for is a function of the form of one of:
distribute :: N (M a) -> M (N a)
joinInner :: M (N (M a)) -> M (N a)
joinOuter :: N (M (N a)) -> M (N a)
that holds for your partiular monads M and N.
IIRC Mark P. Jones wrote a paper or a lib back around '93 that used these
forms of distributive laws to derive monads from the composition of a monad
and a pointed endofunctor.
On Fri, Jul 10, 2009 at 11:34 AM, Job Vranish <jvranish at gmail.com> wrote:
> I'm trying to make a function that uses another monadic function inside a
> preexisting monad, and I'm having trouble.
> Basically my problem boils down to this. I have three monadic functions
> with the following types:
> f :: A -> M B
> g :: B -> N C
> h :: C -> M D
> (M and N are in the monad class)
> I want a function i where
> i :: A -> M (N D)
> the best I can come up with is:
> i :: A -> M (N (M D))
> i a = liftM (liftM h) =<< (return . g) (f a)
> I'm starting to feel pretty sure that what I'm going for is impossible. Is
> this the case?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe