[Haskell-cafe] Re: MonadCatchIO, finally and the error monad
oleg at okmij.org
oleg at okmij.org
Fri Oct 15 04:22:44 EDT 2010
Michael Snoyman wrote:
> I would prefer if the test read as:
>
> > test33 = fmap (== Left "throwError") $ test3c (throwError "throwError" ::
> ErrorT String IO String)
>
> Which never in fact returns True. Or, more to the point, the test is
> never even called, since the runtime exception prevents it.
If you prefer the raised exception to be reflected back into the monad
it came from, that can be arranged. I have updated
http://okmij.org/ftp/Haskell/CaughtMonadIO.lhs
to use your test:
> test331 = fmap (== Left (show "throwError")) $
> test3c (throwError "throwError" :: ErrorT String IO String)
*CaughtMonadIO> test331
sequel called
True
The `show' is the artifact of `reconciling' Error and Exception
classes. The class Error doesn't seem very informative; one may wonder
if it is needed given that we already have Exception. If in your real
code, the argument of throwError is actually an Exception, the show
hack can be eliminated, where it is mentioned in the
instance CaughtMonadIO (ErrorT e m). I can do the adjustment if you
post more details about the desired functionality.
More information about the Haskell-Cafe
mailing list