[Haskell] Bang patterns and declaration order
Iavor Diatchki
iavor.diatchki at gmail.com
Sun Nov 18 15:11:43 EST 2007
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).
Finally, the above program is accepted by GHC 6.8.1 without any
special flags (e.g., no need for -XBangPatterns).
Is this intentional?
--
Iavor
More information about the Haskell
mailing list