Nested pattern binding translates to outermost binding?

Stefan O'Rear stefanor at cox.net
Fri Jul 6 16:46:47 EDT 2007


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 at 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 at stefans:~$ 

Stefan


More information about the Haskell-prime mailing list