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
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to