<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Oct 1, 2013 at 10:24 AM, Alexey Uimanov <span dir="ltr">&lt;<a href="mailto:s9gf4ult@gmail.com" target="_blank">s9gf4ult@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Maybe this is needed new typeclass ApplicativeTrans?</div><div class="gmail_extra"><br><br></div></blockquote>

<div><br></div><div>There&#39;s actually no problem with defining a MonadTrans instance for non-monads. Obviously this can&#39;t follow the laws directly (since they&#39;re defined in terms of monadic bind and return), but I think we could probably state Applicative versions of those laws (assuming I haven&#39;t made a stupid mistake):</div>

<div><br></div><div>lift . pure = pure</div><div>lift (x &lt;*&gt; y) = lift x &lt;*&gt; lift y</div><div><br></div><div>Michael</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="gmail_extra"><div class="gmail_quote">2013/10/1 Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">I&#39;m wondering if anyone&#39;s run into this problem before, and if there&#39;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&#39;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 &lt;$&gt; titleForm &lt;*&gt; something &lt;*&gt; 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&#39;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&#39;t create a MonadIO instance. However, Form is in fact built on top of IO[1]. And it&#39;s possible to create a MonadTrans instance for Form, since it&#39;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" target="_blank">http://haddocks.fpcomplete.com/fp/7.4.2/20130922-179/yesod-form/Yesod-Form-Types.html#t:AForm</a></div>




</div>
<br></div></div><div class="im">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></div></blockquote></div><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div></div>