
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 <$> PF.getFileStatus) filenames
...
The <$> operator evaluates to fmap so it's a cleaner way to apply a pure
function to an IO value.
On Thu, May 6, 2010 at 1:20 AM,
On Thu, 6 May 2010 15:07:30 +1000 Ivan Miljenovic
wrote: On 6 May 2010 15:01,
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 . PF.getFileStatus) filenames
However, I'd be tempted to leave it as is (and hope/assume that fusion does its magic).
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
so now it can operate on the results of getFileStatus, which returns `IO Status`.
mapM gathers the [IO EpochTime] into `IO [EpochTime]` and then <- gives [EpochTime].
It's a little more clear in the verbose form, isn't it ?
Thanks !
Brian _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe