Hi,<div>indeed, this is called &quot;ap&quot; in Control.Monad.  So if we have an instance of Monad, all that needs to be done to support the other instances is:</div><div><br></div><div>instance (SameContextAsTheMonadInstance) =&gt; Functor MyType where fmap = liftM</div>
<div>instance (SameContextAsTheMonadInstance) =&gt; Applicative MyType where pure = return; (&lt;*&gt;) = ap<br><br></div><div>Furthermore, this is only in the cases where we are defining the type from scratch, and not using a library like monadLib or MTL, otherwise a simple &quot;deriving&quot; is sufficient.</div>
<div><br></div><div>-Iavor</div><div><br><div class="gmail_quote">On Wed, Jan 5, 2011 at 12:29 PM, Tony Morris <span dir="ltr">&lt;<a href="mailto:tonymorris@gmail.com">tonymorris@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><div></div><div class="h5">On 06/01/11 04:58, Isaac Dupree wrote:<br>
&gt; Tony, you&#39;re missing the point... Alexey isn&#39;t making a complete patch<br>
&gt; to GHC/base libraries, just a hacky-looking demonstration.  Alexey is<br>
&gt; saying that in a class hierarchy (such as if Functor =&gt; Monad were a<br>
&gt; hierarchy, or for that matter &quot;XFunctor&quot;=&gt;&quot;XMonad&quot; or Eq =&gt; Ord), it<br>
&gt; is still possible to define the superclass functions (fmap) in terms<br>
&gt; of the subclass functions (return and &gt;&gt;=) (such as writing a functor<br>
&gt; instance in which &quot;fmap f m = m &gt;&gt;= (return . f)&quot;).  This has always<br>
&gt; been true in Haskell, it just might not have been obvious.<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Haskell-prime mailing list<br>
&gt; <a href="mailto:Haskell-prime@haskell.org">Haskell-prime@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-prime" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-prime</a><br>
</div></div>Oh right sorry. I thought a stronger point was being made.<br>
<br>
Then perhaps it&#39;s also worth pointing out that (&lt;*&gt;) can be written<br>
using (&gt;&gt;=) and return:<br>
f &lt;*&gt; a = f &gt;&gt;= \ff -&gt; a &gt;&gt;= \aa -&gt; return (ff aa)<br>
<div class="im"><br>
--<br>
Tony Morris<br>
<a href="http://tmorris.net/" target="_blank">http://tmorris.net/</a><br>
<br>
<br>
<br>
_______________________________________________<br>
</div><div><div></div><div class="h5">Haskell-prime mailing list<br>
<a href="mailto:Haskell-prime@haskell.org">Haskell-prime@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-prime" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-prime</a><br>
</div></div></blockquote></div><br></div>