FW: MonadIO needs catch?

Alastair Reid alastair@reid-consulting-uk.ltd.uk
Thu, 06 Feb 2003 11:39:27 +0000

Simon Peyton-Jones <simonpj@microsoft.com> writes:
> This question from John Meacham is really a Libraries Team question.
> Should the MonadIO class get an extra method?  His case looks
> plausible to me.

And to me.  

If the operations only involved 'Monad', I would resist strengthening
the constraint but since it involves the IO monad and exceptions are
an essential part of IO (the real world often fails to behave as
planned), I see no problem.

The only question I see is whether it is best done by adding a

  class Monad m where ...
  class Monad m => MonadCatch m where catch :: ...
  class MonadCatch m => MonadIO m where liftIO :: IO a -> m a


ps This reminds me of an observation Mark P Jones made in the Hugs source
code when he implemented Haskell 1.3 IO.  He pointed out a very
pleasing symmetry between the success operations (>>= and return) and
the failure operations (catch and fail).  They have similar types and
similar semantics.  This symmetry just screams at you if you implement
the IO monad using continuation passing (as Hugs did until last week).