<div dir="ltr">I'm wondering if anyone's run into this problem before, and if there's a common solution.<div><br></div><div>In Yesod, we have applicative forms (based originally on formlets). These forms are instances of Applicative, but not of Monad. Let's consider a situation where we want to get some user input to fill out a blog post datatype, which includes the current time:</div>
<div><br></div><div>data Blog = Blog Title UTCTime Contents</div><div><br></div><div>myBlogForm :: Form Blog</div><div>myBlogForm = Blog <$> titleForm <*> something <*> contentsForm</div><div><br></div>
<div>
The question is: what goes in something? Its type has to be:</div><div><br></div><div>something :: Form UTCTime</div><div><br></div><div>Ideally, I'd call getCurrentTime. The question is: how do I lift that into a Form? Since Form is only an Applicative, not a Monad, I can't create a MonadIO instance. However, Form is in fact built on top of IO[1]. And it's possible to create a MonadTrans instance for Form, since it's entirely possible to lift actions from the underlying functor/monad into Form. So something can be written as:</div>
<div><br></div><div>something = lift $ liftIO getCurrentTime</div><div><br></div><div>This works, but is unintuitive. One solution would be to have an ApplicativeIO typeclass and then use liftIOA. My questions here are:</div>
<div><br></div><div>1. Has anyone else run into this issue?</div><div>2. Is there an existing solution out there?</div><div><br></div><div>Michael</div><div><br></div><div>[1] Full crazy definition is at: <a href="http://haddocks.fpcomplete.com/fp/7.4.2/20130922-179/yesod-form/Yesod-Form-Types.html#t:AForm">http://haddocks.fpcomplete.com/fp/7.4.2/20130922-179/yesod-form/Yesod-Form-Types.html#t:AForm</a></div>
</div>