
9 May
2010
9 May
'10
7:18 a.m.
Pierre-Etienne Meunier wrote:
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.
FWIW, (a >>= (return . f)) == (liftM f a) ~= (fmap f a) Where available, the fmap version is the most efficient. The liftM function can be less efficient since it's defined generically (namely with the bind/return definition above), whereas fmap can take advantage of knowing the specific monad it's working on. But then, not everyone defines Functor instances for their monads... -- Live well, ~wren