[Haskell-cafe] IO Exceptions through monad transformers stack

Nicola Gigante nicola.gigante at gmail.com
Wed Oct 8 09:12:42 UTC 2014


Il giorno 08/ott/2014, alle ore 00:44, Nikita Volkov <nukasu.kanaka at gmail.com> ha scritto:

> Hi Nicola,
> 
Hi!
> Exceptions are a completely unrelated mechanism to all the monad transformers. Roughly speaking, it’s a dirty low level hack into Haskell’s type system. The error-transformer solutions on the other hand are just libraries, which utilize Haskell’s standard features. So there is no relation between the two, other then that they approach the same set of problems.
> 
> Concerning your specific problem, the try function is there to help you. In your final solution you may utilize a function in the spirit of the following:
> 
> data ParserError = 
>   IOError IOException | LexingError <fields> | ParsingError <fields>
> 
> safeLiftIO :: IO a -> Parser a
> safeLiftIO io =
>   liftIO (try io) >>= either (throwError . IOError) return
Thank you, this solves my problem.
I understand that exceptions are a different mechanism from ExceptT
and similar, but I’m still trying to understand how exceptions are supposed
to be integrated with the other error handling mechanisms (or vice versa).

Any pointers to better understand what components are involved and
best practices for addressing this problems?
> Best regards,
> Nikita Volkov
> 
>
Thank you,
Nicola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141008/d2a39850/attachment.html>


More information about the Haskell-Cafe mailing list