[Haskell-cafe] Haskell IO and exceptions

Mark Carroll mark at ixod.org
Fri Dec 10 23:53:49 EST 2004

On Sun, 5 Dec 2004, Scott Turner wrote:
> Yes. Although Control.Monad.Error forces your error type to be in the Error
> class, that puts no constraints on what you save in the errors. If you thread
> your errors with the IO Monad then you would be using the monad:
>    ErrorT YourErrorType IO
> When you invoke runErrorT (within the plain IO monad) it returns an Either
> result which delivers your error type and it can be reported however you
> wish.

Thanks very much! With the help of the StateT example I already had on the
Haskell Wiki I managed to figure out that, to have String errors in ErrorT
for code in the IO monad, I could just pass the strings to throwError,
change the IO Foo functions from which errors might propagate to ErrorT
String IO Foo functions, catch the error in the IO monad with runErrorT
(from the Either), and where I have a function that might throw an error
that uses the result of a normal IO monad function, I lift that result
into the ErrorT monad. And it all seems to work. (-:

-- Mark

More information about the Haskell-Cafe mailing list