[Haskell-cafe] Lists and monads

Vo Minh Thu noteed at gmail.com
Mon Jul 26 09:00:05 EDT 2010

2010/7/26 Kevin Jardine <kevinjardine at gmail.com>:
> As a Haskell neophyte, one of the things I find confusing is the way
> that the usual list functions (map, fold, ++, etc.) often cannot be
> used directly with monadic lists (m [a] or [m a]) but seem to require
> special purpose functions like ap, mapM etc.

Note that this is not specific to lists. For instance you can't directly use

(+) :: Int -> Int -> Int

with values of type

m Int

> I get the idea of separating pure and impure code but am constantly
> frustrated by the fact that stuff that would be easy outside a monad
> seems to get more difficult inside, especially list manipulation. As a
> result I tend to write ugly recursive list functions that would be
> more appropriate with Python, say.
> I suspect that things are not quite as difficult as they appear,
> however, but cannot find any tutorials on monadic list manipulation.
> Any suggestions for resources in that area?

You may look at applicative style programming, with Control.Applicative.

Also, just like with IO, maybe restructuring the code to separate
monadic code would help.


More information about the Haskell-Cafe mailing list