Nested pattern binding translates to outermost binding?

From Haskell' ticket #76: http://hackage.haskell.org/trac/haskell-prime/wiki/BangPatterns
The main idea is to add a single new production to the syntax of patterns pat ::= !pat
Experiments (ghci -fbang-patterns -O2 -S, rename identifiers, then diff) shows that nested pattern bindings are equivalent to the outermost binding: !(!pat) ==> !pat !(~pat) ==> !pat ~(~pat) ==> ~pat ~(!pat) ==> ~pat but I do not see any wording to that effect either in the Haskell 98 report, the GHC documentation, or the Haskell' wiki. Have I overlooked it, or does it follow from the existing language definition? Dan

On Fri, Jul 06, 2007 at 12:08:01PM -0700, Dan Weston wrote:
From Haskell' ticket #76: http://hackage.haskell.org/trac/haskell-prime/wiki/BangPatterns
The main idea is to add a single new production to the syntax of patterns pat ::= !pat
Experiments (ghci -fbang-patterns -O2 -S, rename identifiers, then diff)
You could have just used -ddump-ds... Core is way more readable than GHC assembly.
shows that nested pattern bindings are equivalent to the outermost binding:
!(!pat) ==> !pat !(~pat) ==> !pat
~(~pat) ==> ~pat ~(!pat) ==> ~pat
but I do not see any wording to that effect either in the Haskell 98 report, the GHC documentation, or the Haskell' wiki. Have I overlooked it, or does it follow from the existing language definition?
Pattern matching is completely specified, and from the rules I can derive a counter-example to your assertion. stefan@stefans:~$ ghci -fbang-patterns -v0 Prelude> case 3 of !(!2) -> 'a' *** Exception: <interactive>:1:0-21: Non-exhaustive patterns in case Prelude> case 3 of !(~2) -> 'a' 'a' Prelude> stefan@stefans:~$ Stefan

On Jul 6, 2007, at 1:46 PM, Stefan O'Rear wrote:
You could have just used -ddump-ds... Core is way more readable than GHC assembly.
Great suggestion! Core looks familiar from playing with template Haskell, is it identical? Can one / does anyone use Core as a target for experimental toy languages? Aside from the "moving target" caveats...

On Fri, Jul 06, 2007 at 06:20:45PM -0700, Dave Bayer wrote:
On Jul 6, 2007, at 1:46 PM, Stefan O'Rear wrote:
You could have just used -ddump-ds... Core is way more readable than GHC assembly.
Great suggestion!
Core looks familiar from playing with template Haskell, is it identical?
No, Core is much lower level. It does not have guards, where-blocks, list comprehensions, type classes, etc; everything is reduced to simple pattern bindings, lambdas, lets, applications, and unboxed literals.
Can one / does anyone use Core as a target for experimental toy languages? Aside from the "moving target" caveats...
Apparently not, since GHC's support for *reading* core has been broken since the 6.0 days with nary a complaint. (Aaron Tomb and Tim Chevalier are currently working on fixing it). Stefan

In the section "Changes to the Report" of the Wiki page you refer to http://hackage.haskell.org/trac/haskell-prime/wiki/BangPatterns I attempted to give the semantics of bang-patterns by saying what changes would be needed in the Haskell Report. If you think it's incomplete or ambiguous, then do yell. (The wiki says that the changes are "incomplete" but I can't now think why!) Simon | -----Original Message----- | From: haskell-prime-bounces@haskell.org [mailto:haskell-prime-bounces@haskell.org] On Behalf Of Dan | Weston | Sent: 06 July 2007 20:08 | To: Haskell Prime | Subject: Nested pattern binding translates to outermost binding? | | From Haskell' ticket #76: | http://hackage.haskell.org/trac/haskell-prime/wiki/BangPatterns | | > The main idea is to add a single new production to the syntax | > of patterns | > pat ::= !pat | | Experiments (ghci -fbang-patterns -O2 -S, rename identifiers, then diff) | shows that nested pattern bindings are equivalent to the outermost binding: | | !(!pat) ==> !pat | !(~pat) ==> !pat | | ~(~pat) ==> ~pat | ~(!pat) ==> ~pat | | but I do not see any wording to that effect either in the Haskell 98 | report, the GHC documentation, or the Haskell' wiki. Have I overlooked | it, or does it follow from the existing language definition? | | Dan | | _______________________________________________ | Haskell-prime mailing list | Haskell-prime@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-prime
participants (4)
-
Dan Weston
-
Dave Bayer
-
Simon Peyton-Jones
-
Stefan O'Rear