I've just been through the process of converting some code from using 
Control.Exception to 
using an Error monad, and I would recommend that as a more straightforward and 
manageable alternative, unless you need Control.Exception for other reasons.

I started by changing my potentially-failing functions to return Either 
Exception a,
where Exception is my own user-defined error type, but you could use String, 
and a is the 
type of the "real" return value.  I initially used explicit Left and Right to 
construct appropriate 
values.  My testing code is hand-written, and explicitly matched against Left e 
and Right x to 
decode the return value.

I ended up with functions returning MonadError Exception m => m a, using 
throwError and 
return to construct appropriate values.  My testing code uses
ErrorT Exception (StateT s IO) a
to manage a combination of error-handling, state (an error count) and IO, with 
the option of 
using Either Exception to test expected errors for individual cases.
-- 
Iain Alexander      [EMAIL PROTECTED]


_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to