a faster, accumulating mapM (was Re: [Haskell-cafe] mapM vs mapM_ performance)

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu Apr 24 17:21:43 EDT 2008


Hello Ben,

Friday, April 25, 2008, 1:14:17 AM, you wrote:

mapM2 :: Monad m =>> (a -> m b) -> [a] -> m [b]
> {-# INLINE mapM2 #-}
> mapM2 fn lst = mapM2accum fn lst []
>     where mapM2accum _ [] accum = return accum
>           mapM2accum fn (x:xs) accum = do
>             r <- fn x
>             mapM2accum fn xs (r:accum)

it seems you forget to reverse accum before returning it?


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list