<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 17, 2016 at 3:46 AM, Saurabh Nanda <span dir="ltr"><<a href="mailto:saurabhnanda@gmail.com" target="_blank">saurabhnanda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To generalise the problem, because I've encountered it in other places as well, how does one write his/her own instance of MonadIO, MonadThrow, or MonadCatch for complicated transformer stacks such has ActionCtxT?</blockquote></div><br>You do not generally write MonadIO, you use GeneralizedNewtypeDeriving. But if you insist on writing it yourself:</div><div class="gmail_extra"> instance MonadIO MyMonad ... where liftIO = lift . liftIO</div><div class="gmail_extra">(your MyMonad *must* be an instance of MonadTrans)<br><br>MonadThrow and MonadCatch, I suggest you refer to their documentation. But I will tell you that writing this kind of exception management, in such a way that you do not leak resources (memory, file handles, database connections, ...), is *very hard*. You probably should not attempt it unless you have experience with this. (I won't even try to write one; I understand the basic issues, but lack specific experience with how to deal with them in ghc and with specific exception mechanisms like MonadThrow/MonadCatch and MonadBaseControl.)<br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>brandon s allbery kf8nh sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a> <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div></div>
</div></div>