[Haskell] Bang patterns and declaration order
lennart at augustsson.net
Sun Nov 18 17:47:15 EST 2007
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.
On Nov 18, 2007 8:34 PM, Derek Elkins <derek.a.elkins at gmail.com> 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 at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell