Hi,<div>indeed, this is called "ap" 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) => Functor MyType where fmap = liftM</div>
<div>instance (SameContextAsTheMonadInstance) => Applicative MyType where pure = return; (<*>) = 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 "deriving" 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"><<a href="mailto:tonymorris@gmail.com">tonymorris@gmail.com</a>></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>
> Tony, you're missing the point... Alexey isn't making a complete patch<br>
> to GHC/base libraries, just a hacky-looking demonstration. Alexey is<br>
> saying that in a class hierarchy (such as if Functor => Monad were a<br>
> hierarchy, or for that matter "XFunctor"=>"XMonad" or Eq => Ord), it<br>
> is still possible to define the superclass functions (fmap) in terms<br>
> of the subclass functions (return and >>=) (such as writing a functor<br>
> instance in which "fmap f m = m >>= (return . f)"). This has always<br>
> been true in Haskell, it just might not have been obvious.<br>
><br>
> _______________________________________________<br>
> 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>Oh right sorry. I thought a stronger point was being made.<br>
<br>
Then perhaps it's also worth pointing out that (<*>) can be written<br>
using (>>=) and return:<br>
f <*> a = f >>= \ff -> a >>= \aa -> 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>