[Haskell-beginners] forM vs mapM

Thomas Davie tom.davie at gmail.com
Thu Aug 19 06:08:34 EDT 2010


On 19 Aug 2010, at 11:02, Gaius Hammond wrote:

> Hi all,
> 
> 
> Can anyone give me an example of a situation where you would use forM but *not* mapM or vice versa? As far as I can see one is simply a flip of the other. Does forM make any guarantees about order of execution?

Nope, no extra guarentees, just reverses the argument order.

forM can look quite nice if you have a large function that you want to map...

forM [someList]
  lots of
  large function
  here
  ...

while mapM can look good if you have a small function...
mapM simpleFunction [someList]

They're also useful both ways round partially applied.

Bob


More information about the Beginners mailing list