[Haskell-cafe] Haskell IO and exceptions

Scott Turner p.turner at computer.org
Sun Dec 5 00:42:29 EST 2004


On 2004 December 02 Thursday 09:35, Mark Carroll wrote:
> I like Control.Monad.Error but often my stuff is threaded through
> the IO monad so, AFAICT from the functional dependency stuff, that means
> my errors have to be IOErrors. Is that right? And, then, I want control
> over what's actually reported to the user, but if I make a userError than
> the consequent message (where the details are presumably
> platform-dependent) is wrapped up in extra text that I didn't want
> appearing. Can I use Control.Monad.Error for IO monad stuff such that I
> can control what string will appear when my error handler tries to "show"
> my exception?

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.

Note that there is no integration between the error tracking of ErrorT, and IO 
error handling.  If your code currently calls userError, it would have to be 
modified.


More information about the Haskell-Cafe mailing list