Bang patterns

Simon Peyton-Jones simonpj at
Mon Feb 4 23:37:44 CET 2013

|  > I have two proposals, I suppose:
|  > - make bang patterns operate only on variables and wildcards
|  > - make bang patterns in let altogether invalid
|  Looking at this again made me realise that, as well as !_ and !varid
|  lexemes, we could also alter the decl production so that we get
|      decl -> ...
|            | pat rhs     -- existing lazy binding production
|            | '!' pat rhs -- new strict binding production
|  That means that
|      let !(x, y) = e in ...
|  would still be valid, with the ! not actually being parsed as part of
|  the pattern, but would parse instead as a strict binding. 

Yes, I like this.  You could see the 
	'!' pat rhs
production as cancelling the implied '~' that a let-binding usually gets (see the desugaring for lets in the report).

A bang really only makes sense
* At the top of a let, to cancel the implied '~'.  Like Johan I
   am very strongly in favour of using ! for this purpose.
* On a varid or '_', which otherwise match lazily
Hence Ian's proposal, which treats these two separately, makes sense.

For example, there's no point in the pattern (x, !(y,z)), because it behaves identically to (x, (y,z)).

We really do need to allow
	f  !x  y !z = e
to mean f is strict in x and z.  There is an ambiguity here with a infix definition of (!), but it must be resolved in favour of the bang-pattern version.

I don't have a strong opinion about whether
	f ! x y ! z = e
should mean the same; ie whether the space is significant.   I think it's probably more confusing if the space is significant (so its presence or absence makes a difference).


More information about the Haskell-prime mailing list