[Haskell-cafe] Use unsafePerformIO to catch Exception?
lennart at augustsson.net
Wed Mar 25 12:31:47 EDT 2009
If you think non-determinstic programs are acceptable, then you can
use unsafePerformIO this way.
But future versions of compilers may make them even more
unpredictable, so beware.
I think that if the exception handler does not look at exactly what
exception was thrown, then the program will just vary in definedness
(i.e., comparable in the domain approximation ordering).
Many people consider this acceptable.
On Wed, Mar 25, 2009 at 4:15 PM, Donn Cave <donn at avvanta.com> wrote:
> Quoth Lennart Augustsson <lennart at augustsson.net>:
>> Some examples of what might happen:
> OK, these are interesting phenomena. From a practical point of view,
> though, I could see someone weighing the potential costs and benefits
> of a exception handler outside IO like this, and these effects might
> not even carry all that much weight. Does that make sense, or is the
> problem really more dire than I understand?
> I mean, it isn't the first time I've seen this explained in terms of
> predictability in a case where there are two possible exceptions, so
> I have to take for granted that this is a compelling argument to some,
> but it is evidently a matter of perspective.
>> If you have more than one possible exception in your code, you don't
>> know which one you will get.
>> It can vary between compilers, optimization levels, program runs, or
>> even evaluating the same expression within one program.
>> If you have code that have both an infinite loop and an exception you
>> don't know if you'll get the loop or the exception.
>> Breaking the deterministic behaviour can lead to strange consequences,
>> because the compiler relies on it.
>> For instance, the following code
>> let x = someExpression
>> print x
>> print x
>> could print different values for x the two times you print it.
>> (This is somewhat unlikely, but could happen when evaluating in
>> parallel with ghc, because there is a small window where two threads
>> might start evaluating x and later update x with two different
>> -- Lennart
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe