[Haskell-cafe] Monadic Composition

Jorge Adriano Aires jadrian at mat.uc.pt
Wed May 12 16:01:35 EDT 2004

> So, yes, it is useful, but should it be included in a standard Monad
> module? After all, this module contains mostly trivial functions ;)
> BTW. You can write this function using foldM:
>     compM l a = foldM (#) a l
> where # is an often used reverse application operator:
>     x # f = f x

Right. Now that I look at it, someone probably tried to give me this advice 
before but I failed to understand... (sorry monotonom!). It's all clear now. 
One more question. Isn't the foldM description a bit misleading? From the 
Report and also in GHC documentation:

"The foldM function is analogous to foldl, except that its result is 
encapsulated in a monad.(...)
foldM f a1 [x1, x2, ..., xm ] == 
          a2 <- f a1 x1
          a3 <- f a2 x2
          f am xm"

After reading this I expected "left associativity", just like in my first 
definition. That'd mean a fail wouldn't stop a computation immediately but 
instead be passed from function to function. By checking its definition in 
the report I can see this is not the case though.


More information about the Haskell-Cafe mailing list