[Haskell-cafe] Absolutely confused with error/exception handling

Brandon Allbery allbery.b at gmail.com
Fri Dec 16 03:44:00 UTC 2016


On Thu, Dec 15, 2016 at 10:30 PM, Saurabh Nanda <saurabhnanda at gmail.com>
wrote:

>
> Any reason for "error" and "catch" to be in different packages? Or, why
> isn't "catch" in prelude?
>
> "catch" needs a action in IO. What if I have an action in MonadIO?
>

A version of `catch` used to be in Prelude, but it *only* worked with the
IOException subtype; the one in Control.Exception works for all exception
types. Rather than propagate the confusion between them, or risk breaking
code in weird ways (the one in Prelude was restricted in part because the
exception system was redesigned to be extensible, and the Prelude version
didn't handle the way the new exception types work), it was simply removed.
The Prelude one was something of an oddity even before extensible
exceptions and mostly confused new Haskellers, so there didn't seem to be
much reason to keep it around.

MonadIO is going to be hard. It's not a type but a typeclass for things
that can perform operations in IO; but this is not (and can't be, if you
think about it) bidirectional. Consider the case of StateT s IO: your
exception handler can get an `s` known when the `catch` is evaluated, but
can never know the *current* value of the `s` when the exception is thrown
--- exceptions do not know how to carry state around like that, and in the
most general case can't know how. There are various frameworks that attempt
to add this kind of functionality, such as MonadCatch and MonadBaseControl;
but it's fairly tricky even at the best of times.

-- 
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/20161215/75b8d16e/attachment.html>


More information about the Haskell-Cafe mailing list