On Sat, Dec 17, 2016 at 3:46 AM, Saurabh Nanda <saurabhnanda@gmail.com> wrote:
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?

You do not generally write MonadIO, you use GeneralizedNewtypeDeriving. But if you insist on writing it yourself:
  instance MonadIO MyMonad ... where liftIO = lift . liftIO
(your MyMonad *must* be an instance of MonadTrans)

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.)

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net