In the previous article we showed how to derive and use the Maybe and list
monads. In this article and the next we're going to look at how to use monads
for error handling, also known as exception handling.
In the previous
article we discussed error-handling strategies in Haskell and derived the
Either e monad for structured error handling. In this article
we'll continue our discussion of error handling by introducing some new type
classes that will enable us to write code which recovers from errors in a
selective way (which is called exception handling in most computer
languages). Interestingly, exception handling doesn't have to be built-in in
Haskell; you get it for free once you have monads!
I also promise (threaten?) that there will be one absolutely jaw-droppingly
awful pun in what follows. You have been warned.