<div dir="ltr"><div class="gmail_default"><font face="arial, helvetica, sans-serif">You could perhaps write </font><font face="courier new, monospace">MyWierdMonadT</font><font face="arial, helvetica, sans-serif"> and </font><font face="courier new, monospace">MyAnotherMonadT</font><font face="arial, helvetica, sans-serif">.</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">Also, probably layers package [1] is related to what you ask.</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">But if you actually want arbitrary nested monads like </font><font face="courier new, monospace">m1 (m2 (m3 (m4 a)))</font><font face="arial, helvetica, sans-serif">, there's no simple way.</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif">Consider </font><font face="courier new, monospace">Maybe [MyType Int]</font><font face="arial, helvetica, sans-serif">. </font><font face="courier new, monospace">MyType</font><font face="arial, helvetica, sans-serif"> may have or may not have a </font><font face="courier new, monospace">Monad</font><font face="arial, helvetica, sans-serif"> instance. Even more: it can have instance in one module, but not have in another. But suppose </font><font face="courier new, monospace">MyType</font><font face="arial, helvetica, sans-serif"> has a </font><font face="courier new, monospace">Num</font><font face="arial, helvetica, sans-serif"> instance. Then how this should work: </font><font face="courier new, monospace">return 2 :: Maybe [MyType Int]</font><font face="arial, helvetica, sans-serif">? Should </font><font face="courier new, monospace">2</font><font face="arial, helvetica, sans-serif"> be of type </font><font face="courier new, monospace">Int</font><font face="arial, helvetica, sans-serif"> or </font><font face="courier new, monospace">MyType</font><font face="arial, helvetica, sans-serif"> </font><font face="courier new, monospace">Int</font><font face="arial, helvetica, sans-serif">?</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">Note that you can make an </font><font face="courier new, monospace">instance Num a => Num [a]</font><font face="arial, helvetica, sans-serif"> which makes sense (lists as polynoms). So the same question arises even for </font><font face="courier new, monospace">Maybe [Int]</font><font face="arial, helvetica, sans-serif">.</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">If you <i>*really want to do it*</i> (which I doubt), you can use TH (do determine how many return's to use, though it's ambiguous anyway).</font></div>
<div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">[1] <a href="http://hackage.haskell.org/package/layers-0.1/docs/Documentation-Layers-Overview.html" style="font-family:arial">http://hackage.haskell.org/package/layers-0.1/docs/Documentation-Layers-Overview.html</a></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/11/23 Dmitry Bogatov <span dir="ltr"><<a href="mailto:KAction@gnu.org" target="_blank">KAction@gnu.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
> Perhaps you just want monad transformers [1, 2]. If you're not familiar<br>
> with them, you should probably read [3].<br>
><br>
> With transformers you'd be able to do this (and more):<br>
><br>
> $ return 2 :: IO Int<br>
> $ return 2 :: ListT Maybe Int   -- this works like Maybe [Int]<br>
> $ return 2 :: MaybeT [] Int     -- this works like [Maybe Int]<br>
<br>
</div>In fact, I read and used transformers a bit. If I understand correctly,<br>
I can only do such things for monads, supported by transformers. So,<br>
<br>
I cant get (return 2) :: MyWierdMonad (MyAnotherMonad 2)<br>
<br>
Yes, I know, it have little practical use, but I am insterested about<br>
teoretical part of question, magic of ghc.<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
Best regards, Dmitry Bogatov <<a href="mailto:KAction@gnu.org">KAction@gnu.org</a>>,<br>
Free Software supporter and netiquette guardian.<br>
        git clone git://<a href="http://kaction.name/rc-files.git" target="_blank">kaction.name/rc-files.git</a> --depth 1<br>
        GPG: 54B7F00D<br>
Html mail and proprietary format attachments are forwarded to /dev/null.<br>
</div></div></blockquote></div><br></div>