[Haskell-cafe] mixing map and mapM ?

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Thu May 6 08:44:18 EDT 2010


Pierre-Etienne Meunier <pierreetienne.meunier at gmail.com> writes:

> This way :
>
> do
> 	times<-mapM PF.getFileStatus filenames >>= return.(map PF.modificationTime)
>
> Or also :
>
> do
> 	times<-mapM (PF.getFileStatus >>= (return.(PF.modificationTime))) filenames
> 	let sorted=...
>
> I do not know exactly how ghc compiles the IO monad, but it seems to
> me that the latter would allocate a little less.

List fusion probably converts them to the same core (you can always use
ghc-core to verify this if you care).

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list