Re: [Haskell-cafe] mixing map and mapM ?

2010-05-09 Thread wren ng thornton
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

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-09 Thread Brandon S. Allbery KF8NH
On May 9, 2010, at 07:18 , wren ng thornton wrote: 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

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Bill Atkins
Almost - liftM modificationTime has type Status - IO EpochTime. Like other IO functions (getLine, putStrLn), it returns an IO action but accepts a pure value (the modification time) Also, I like this style: import Control.Applicative (($)) blah = do times - mapM (PF.modificationTime $

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Neil Brown
Bill Atkins wrote: Almost - liftM modificationTime has type Status - IO EpochTime. Like other IO functions (getLine, putStrLn), it returns an IO action but accepts a pure value (the modification time) Also, I like this style: import Control.Applicative (($)) blah = do times - mapM

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Ben Millwood
On Thu, May 6, 2010 at 11:51 AM, Bill Atkins watk...@alum.rpi.edu wrote: Almost - liftM modificationTime has type Status - IO EpochTime.  Like other IO functions (getLine, putStrLn), it returns an IO action but accepts a pure value (the modification time) ghci :m +Control.Monad

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Bill Atkins
Yep, you and Ben are both correct. Mea culpa and sorry for the bad answer. Just curious: why does getModificationTime take an IO FileStatus rather than a FileStatus? On Thu, May 6, 2010 at 7:00 AM, Neil Brown nc...@kent.ac.uk wrote: Bill Atkins wrote: Almost - liftM modificationTime has

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Ben Millwood
On Thu, May 6, 2010 at 12:37 PM, Bill Atkins watk...@alum.rpi.edu wrote: Just curious: why does getModificationTime take an IO FileStatus rather than a FileStatus? It doesn't. getModificationTime is a pure function (think of it like a record accessor). liftM makes it take IO FileStatus

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Pierre-Etienne Meunier
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

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread Ivan Lazar Miljenovic
Pierre-Etienne Meunier pierreetienne.meun...@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

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-06 Thread briand
On Thu, 06 May 2010 12:00:01 +0100 Neil Brown nc...@kent.ac.uk wrote: At which point I prefer Ivan's liftM version rather than the above section (or worse: using ($) prefix). The original request is a relatively common thing to want to do, so I was slightly surprised that hoogling for:

[Haskell-cafe] mixing map and mapM ?

2010-05-05 Thread briand
I was doing the following: do status - mapM PF.getFileStatus filenames let times = map PF.modificationTime status let sorted = sortBy (\(_, t1) (_,t2) - compare t1 t2) (zip filenames times) and I thought, surely I can combine the status and times definitions into one line, only I can't.

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-05 Thread Ivan Miljenovic
On 6 May 2010 15:01, bri...@aracnet.com wrote: I was doing the following: do status - mapM PF.getFileStatus filenames   let times = map PF.modificationTime status   let sorted = sortBy (\(_, t1) (_,t2) - compare t1 t2) (zip filenames times) times - mapM (liftM PF.modificationTime .

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-05 Thread briand
On Thu, 6 May 2010 15:07:30 +1000 Ivan Miljenovic ivan.miljeno...@gmail.com wrote: On 6 May 2010 15:01, bri...@aracnet.com wrote: I was doing the following: do status - mapM PF.getFileStatus filenames   let times = map PF.modificationTime status   let sorted = sortBy (\(_, t1)

Re: [Haskell-cafe] mixing map and mapM ?

2010-05-05 Thread Ivan Miljenovic
On 6 May 2010 15:20, bri...@aracnet.com wrote: well now it's obvious :-)  I did have liftM in there, but just couldn't quite figure out how to tie things together. to be completely clear : liftM takes modificationTime from  Status - EpochTime to  IO Status - IO EpochTime You can see it