Luke, Thanks for the nice answer. So maybe I'll give mapM3 the name mapM' and put it in my personal library. But I'm still a bit curious about the performance profile of mapM. The profiler is telling me they're allocating around the same amount of memory, so I am not clear what is making it slow. I am guessing it has something to do with extra thunks due to laziness, but a 10x slowdown? Thanks again, B On Thu, Apr 24, 2008 at 4:45 PM, Luke Palmer <lrpalmer@gmail.com> wrote:
On Thu, Apr 24, 2008 at 11:28 PM, Ben <midfield@gmail.com> wrote:
2) Is there a reason to not use mapM3 above?
Yes, there certainly is. mapM3 is not equivalent to mapM; it is too strict:
*Main> take 3 $ head $ mapM return [1,2,3,4,undefined] [1,2,3] *Main> take 3 $ head $ mapM3 return [1,2,3,4,undefined] [*** Exception: Prelude.undefined
So, like foldl', mapM3 seems a viable alternative for mapM, but not a replacement.
Luke