Suggestion for bang patterns documentation

Christian Maeder Christian.Maeder at dfki.de
Fri Feb 27 05:53:22 EST 2009


Brian Bloniarz wrote:
> I got confused by the GHC documentation recently, I was wondering how
> it could be improved. From:
> http://www.haskell.org/ghc/docs/latest/html/users_guide/bang-patterns.html

Seeing the rule
 pat ::= !pat

you'll probably want to avoid patterns like: "!!pat", "! ! pat", or "~ !
~ pat".

Even the current http://www.haskell.org/onlinelibrary/exps.html#sect3.17.1

  apat -> ~ apat

allows "~ ~x". (Note the space!) So maybe a separate non-terminal "bpat"
should be used with:

 bpat -> [~|!] apat

(and bpat used within pat). You may also want to exclude "v@ ~(...)" in
favor of "~v@(...)".

>> A bang only really has an effect if it precedes a variable or wild-card pattern:
>> f3 !(x,y) = [x,y]
>> f4 (x,y)  = [x,y]
>> Here, f3 and f4 are identical; putting a bang before a pattern that
>> forces evaluation anyway does nothing.

Maybe the duality (if it is one) should be added that an irrefutable
pattern above would make a difference but not within the let below.

> The first sentence is true, but only in settings where the pattern is being
> evaluated eagerly -- the bang in:
>> f3 a = let !(x,y) = a in [1,x,y]
>> f4 a = let (x,y) = a in [1,x,y]
> has an effect.

Cheers Christian



More information about the Glasgow-haskell-users mailing list