[Haskell-cafe] The errorCalls and ioErrors in extensible exceptions way

Gracjan Polak gracjanpolak at gmail.com
Wed Feb 3 10:45:20 EST 2010

Hi all,

I have base==3.* code that uses errorCalls and ioErrors to intercept either
ErrorCall or IOError that may arise in deeper code.

I'd like to convert this code to base==4.* new exceptions.

-- | Evaluate the argument and catch error call exceptions
errorToErr :: Monad m => a -> Err m a
errorToErr x = let e = unsafePerformIO (tryJust errorCalls (evaluate x))
		   in ErrorT (return e)

-- | Catch IO errors in the error monad.
ioErrorToErr :: IO a -> Err IO a
ioErrorToErr = ErrorT . liftM (either (Left . show) Right) . tryJust ioErrors

Look here for more context:


I know that just importing OldException will do the trick for now. But I'd like
to know how to do such a trick in extensible exceptions way.

Also that unsafePerformIO looks a bit scary. Isn't there a better way to achieve


More information about the Haskell-Cafe mailing list