[Haskell-cafe] Re: throwDynIO ?

Aleksey Nogin anogin at hrl.com
Fri May 23 14:04:35 EDT 2008


Back in October'06 Carlos Pita sent a message to this list:

> Currently I'm trying to grasp haskell exception handling and although
> I find it mostly clear I'm a bit confused regarding the lack of a
> throwDynIO action "paralelling" throwIO, as there are dynamic variants
> for the other throw functions:
> 
> throwDyn  - throw
> throwDynTo - throwTo
> 
> I understand that the same effect could be conjured up by
> 
> throwIO (DynException (...)))
> 
> magic. But the lack of symmetry still disturbes me. Am I missing something?

As far as I can tell, his question was left unanswered. As another 
Haskell newcomer (crossing over from the OCaml world), I found the 
absence of throwDynIO weird as well - as far as I understand things, 
throwing an error in the IO monad seems like a safer thing to do (as I'd 
know precisely when to expect it to be raised) than throwing it from a 
pure code and then relying on the "imprecise exceptions" mechanism to 
get it right.

Looking at the ghc-6.8.2/libraries/base/Control/Exception.hs in the GHC 
source code, I see the following definitions:

throw = unsafePerformIO . throwIO
throwDyn exception = throw (DynException (toDyn exception))

so I guess I can get define throwDynIO myself by "taking back" the 
unsafePerformIO:

throwDynIO exception = throwIO (DynException (toDyn exception))

but I am still wondering whether the library is simply incomplete here, 
or whether there is some reason for not defining/using throwDynIO.

Thanks in advance for any clarifications!

Aleksey


More information about the Haskell-Cafe mailing list