[Haskell-beginners] Getting the current system date outside the IO Monad

Chaddaï Fouché chaddai.fouche at gmail.com
Tue Dec 27 09:53:08 CET 2011


On Tue, Dec 27, 2011 at 9:41 AM, AbdulSattar Mohammed
<codingtales at gmail.com> wrote:
> I'm still learning Haskell and I've started learning Yesod. I pretty much
> built a blog before I came this silly roadblock.
>
> Whenever I create a new post, I want it take the current system time as its
> creation time. I understand it's an impure operation and it must go into the
> IO Monad to be performed. But, in Yesod, your handler is of the type Handler
> RepHtml. I don't get how you could get the impure value into a pure function
> without main playing any part.
>

Thankfully, we can build monad "stacks" that contains several
capacities, this is a standard way to design libraries in Haskell.
Yesod use Handler and not IO because it needs to convey more
informations than just the IO monad but Handler normally contains IO
and is as such a MonadIO instance. In other words, you can use any IO
action with the "liftIO" function.

-- 
Jedaï



More information about the Beginners mailing list