[Haskell-cafe] Absolutely confused with error/exception handling
Brandon Allbery
allbery.b at gmail.com
Sat Dec 17 03:57:45 UTC 2016
On Sat, Dec 17, 2016 at 3:46 AM, Saurabh Nanda <saurabhnanda at 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 at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161217/a6f33794/attachment.html>
More information about the Haskell-Cafe
mailing list