ANN control-monad-exception-0.1: Explicitly typed exceptions
The control-monad-exception package  provides explicitly typed
exceptions for Haskell.
In other words, this is a perfect example of bundling in a Haskell
library what for other
programming languages is a native feature.
The type of a computation in the EM monad carries a list of the exceptions that
the computation may throw. A exception is raised with 'throw', which
in addition adds it
to the type, and captured with 'catch', which correspondingly removes
it from the type.
Only safe computations (all exceptions handled) can escape from the monad.
The encoding used for the exception list is based on a phantom type
variable carrying a
@Throws@ constraint for every exception type. Catching an exception
@e@ satifies the constraint
@Throws e@ thus removing it from the type. It is possible to teach
Throws about exception subtyping
by manually inserting new instances declaring the subtyping relations
between exceptions. I don't
believe there is a better way to handle this, as the existential
wrapper encoding used
for Control.Exception.SomeException does not reveal the subtyping
relations, but ideas are
GHCi infers the following types
eval :: (Throws DivideByZero l, Throws SumOverflow l) => Expr -> EM l Double
eval `catch` \ (e::DivideByZero) -> return (-1) :: Throws
SumOverflow l => Expr -> EM l Double
runEM (eval `catch` \ (e::SomeException) -> return (-1)) :: Expr -> Double