Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Iavor Diatchki <iavor.diatchki <at> gmail.com>
Subject: Bang patterns and declaration order
Newsgroups: gmane.comp.lang.haskell.general
Date: Sunday 18th November 2007 20:11:43 UTC (over 9 years ago)
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
 
CD: 3ms