Discussion:
[Haskell-beginners] forM vs mapM
Gaius Hammond
2010-08-19 10:02:22 UTC
Permalink
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?


Thanks,


G



------------------
Thomas Davie
2010-08-19 10:08:34 UTC
Permalink
Post by Gaius Hammond
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
Gaius Hammond
2010-08-19 10:16:06 UTC
Permalink
Thanks, I suspected that might be the case but it seemed too simple :-)



Cheers,



G



------------------

-----Original Message-----
From: Thomas Davie <***@gmail.com>
Date: Thu, 19 Aug 2010 11:08:34
To: <***@Gaius.org.UK>
Cc: Haskell Beginners List<***@haskell.org>
Subject: Re: [Haskell-beginners] forM vs mapM
Post by Gaius Hammond
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 wa

Loading...