Bang patterns, ~ patterns, and lazy let

Simon Peyton-Jones simonpj at
Wed Feb 8 04:54:32 EST 2006

| The trouble with those parts is that NOWHERE do they discuss how to
| translate a let or where containing more than one binding. If they're
| not to be translated via tupling, then how are they to be translated?

Sorry I wasn't clear.  Given 
	let { p1 = e1; ... ; pn = en } in e0

(P1)  For each pattern pi that is of form !qi = ei, transform it to
	xi at qi = ei
and replace e0 by (xi `seq` e0)

(P2)  Now no pattern has a ! at the top.  Now apply the existing rules
3.12 of the Haskell report.

So step (P1) above adds some seqs, and after that it's all just standard
Haskell 98.

My summary so far:

1) Bang patterns by themselves are quite decent, well-behaved patterns.

2) Rule (P1) is simple to describe.   But the ! in a pattern binding is
treated as part of the *binding* rather than part of the *pattern* which
is wart-y.

3) There is a good argument to be made that pattern bindings should be
strict by default.  That is
	let (x,y) = e in b
would evaluate e strictly.  However that is *not* the same as saying
that 'let' is strict.  
	let x = e in b
remains a lazy binding of x (because, as usual, a variable pattern
matches without evaluation).

4)  John argues that it would be bad to adopt bang patterns without also
adopting (3).  I don't agree.  But I'm still attracted by (3).

I will add some of this to the Wiki.  Please do not treat it as "my"
page --- any committee member can edit it.


More information about the Haskell-prime mailing list