Why no exceptions in Haskell?

Keith Wansbrough Keith.Wansbrough@cl.cam.ac.uk
Thu, 22 Nov 2001 18:50:31 +0000

> Hello *,
> I am just curious: Why does Haskell not provide exceptions a la SML?
> Why does only the IO monad allow for exceptions?

GHC certainly implements exceptions, along the lines described in

  A semantics for imprecise exceptions, Simon Peyton Jones, Alastair
  Reid, Tony Hoare, Simon Marlow, Fergus Henderson. Proc Programming
  Languages Design and Implementation (PLDI'99), Atlanta.


As described there,
 * you can *raise* an exception anywhere,
 * but you can only *catch* an exception in the IO monad.

This is essentially because exceptional behaviour is `impure', and
Haskell's way of dealing with impure behaviour (like files, user
input, global state, and so on) is via the IO monad.

HTH.  There's more in the paper.

--KW 8-)