On Dec 11, 2007 1:29 PM, apfelmus &lt;<a href="mailto:apfelmus@quantentunnel.de">apfelmus@quantentunnel.de</a>&gt; wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Without the automatic search, this is already possible<br><br> &nbsp; &nbsp; class Functor f where<br> &nbsp; &nbsp; &nbsp; &nbsp; fmap :: (a -&gt; b) -&gt; f a -&gt; f b<br><div class="Ih2E3d"><br> &nbsp; &nbsp; class Functor m =&gt; Monad m where<br></div> &nbsp; &nbsp; &nbsp; &nbsp; return :: a -&gt; m a
<br> &nbsp; &nbsp; &nbsp; &nbsp; (&gt;&gt;=) &nbsp;:: m a -&gt; (a -&gt; m b) -&gt; m b<br><br> &nbsp; &nbsp; &nbsp; &nbsp;-- aka liftM<br> &nbsp; &nbsp; fmapDefault :: Monad m =&gt; (a -&gt; b) -&gt; m a -&gt; m b<br> &nbsp; &nbsp; fmapDefault f m = m &gt;&gt;= (return . f)<br><br> &nbsp; &nbsp; instance Monad [] where
<br> &nbsp; &nbsp; &nbsp; &nbsp; return x = [x]<br> &nbsp; &nbsp; &nbsp; &nbsp; (&gt;&gt;=) &nbsp; &nbsp;= flip concatMap<br><br> &nbsp; &nbsp; instance Functor [] where<br> &nbsp; &nbsp; &nbsp; &nbsp; fmap = fmapDefault<br><br> &nbsp;fmap &nbsp;is already written for you, the instance declaration is only<br>boilerplate. I first saw this in &nbsp;
Data.Traversable .<br></blockquote><div>&nbsp;<br>This is pretty much how I define Functor and Applicative instances for my monads. It is admittedly irritating to have to write out the boilerplate, but&nbsp; it doesn&#39;t seem irritating enough to require a language extension to eliminate.
<br><br></div></div>-- <br>Dave Menendez &lt;<a href="mailto:dave@zednenem.com">dave@zednenem.com</a>&gt;<br>&lt;<a href="http://www.eyrie.org/~zednenem/">http://www.eyrie.org/~zednenem/</a>&gt;