[Haskell-cafe] mixing map and mapM ?

Ivan Miljenovic ivan.miljenovic at gmail.com
Thu May 6 01:25:09 EDT 2010


On 6 May 2010 15:20,  <briand at 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 that way, yes (of course, liftM works on all monads,
not just IO).

> so now it can operate on the results of getFileStatus, which
> returns `IO Status`.

Operate directly on the returned values; you could always use
something like "(return . modificationTime) =<< getFileStatus file" as
well.

> mapM gathers the [IO EpochTime] into `IO [EpochTime]` and then <- gives
> [EpochTime].

No, it's the sequence function that does that (but mapM f = sequence . map f).

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


More information about the Haskell-Cafe mailing list