Right.  Still, it's a point worth noting. I've added a short section to
                http://hackage.haskell.org/trac/haskell-prime/wiki/BangPatterns
which in turn is referred to from the GHC manual.

Simon

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Lennart 
Augustsson
Sent: 18 November 2007 22:47
To: Derek Elkins
Cc: Haskell users
Subject: Re: [Haskell] Bang patterns and declaration order

I totally agree with Derek.  Which exception you get can vary with compiler 
version, compiler flags, time of day, phase of the moon, ...
It will be one in a set of exceptions, but you don't know which one.

  -- Lennart
On Nov 18, 2007 8:34 PM, Derek Elkins <[EMAIL PROTECTED]<mailto:[EMAIL 
PROTECTED]>> wrote:
On Sun, 2007-11-18 at 12:11 -0800, Iavor Diatchki wrote:
> Hello,
>
> I was playing around with "bang patterns" and I noticed that
> when combined with asynchronous exceptions they can lead to
> programs where the order of the declarations in a binding
> group is important!  Here is an example:
>
> > import Control.Exception
> > import Prelude hiding (catch)
> >
> > main = putStrLn =<< eval_order
> >
> > test = "no exception"
> >   where !_ = error "top down"
> >         !_ = error "bottom up"
> >
> > eval_order = evaluate test `catch` \e ->
> >                case e of
> >                  ErrorCall txt -> return txt
> >                  _             -> throw e
>
> Of course, this is a contrived exampled but, as far as I know,
> this was not possible in Haskell before (if anyone has an example
> to the contrary please send it to the list).
>
> By the way, with GHC 6.8.1 the above program prints "bottom up".
> This means that when there are multiple "banged" bindings they
> are evaluated starting with the last one in the text.  I imagine
> than in most programs this is not particularly important, but
> it seems to me that it would be a bit nicer if we were to adjust
> the translation so that bindings were evaluated top to bottom
> (e.g., like in ML).
The whole point of the "imprecise exceptions" paper was that any
exception may be returned when multiple ones could be.  There is no
reason why the bindings should be evaluated top-down.  If you are
relying on the order the bindings are evaluated you are doing something
very, very wrong.  Should we also specify what exception should be
thrown for  error "left-right" + error "right-left" ?

_______________________________________________
Haskell mailing list
Haskell@haskell.org<mailto:Haskell@haskell.org>
http://www.haskell.org/mailman/listinfo/haskell

_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to