FW: MonadIO needs catch?

Simon Peyton-Jones simonpj@microsoft.com
Thu, 6 Feb 2003 09:38:07 -0000

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.


-----Original Message-----
From: John Meacham [mailto:john@repetae.net]=20
Sent: 28 January 2003 06:35
To: haskell@haskell.org
Subject: MonadIO needs catch?

while genericizing my utility libraries to work within any MonadIO
I ran into a problem, 'liftIO' is not powerful enough to catch
exceptions in a MonadIO.=20
the closest one can get is=20

> genCatch :: MonadIO m =3D> IO a -> (Exception -> IO a) -> m a
when we want..
> genCatch :: MonadIO m =3D> m a -> (Exception -> m a) -> m a

The only way i can think of to solve this is add 'catch' (perhaps
'catchIO'? 'genCatch'?) to the MonadIO class.=20

some open questions are whether it is possible to implement catch for
any MonadIO? I would think so, since you need only store the 'internal
state' of your monad at the genCatch and continue with that if an
exception was raised. (this might mix badly with other extensions
though?) at worst a MonadIOCatchable deriving from MonadIO could be


John Meacham - California Institute of Technology, Alum. - john@foo.net
Haskell mailing list