bugs from n+k patterns (was: Re: Preventing/handling space leaks)

John Peterson peterson-john at cs.yale.edu
Thu Dec 11 14:55:59 EST 2003

The n+k pattern issue inspired endless debates on the Haskell
committee and this feature was considered for removal in nearly every
iteration of the Haskell report.  We all agreed that n+k is extremely ad-hoc but
that certain programs can be expressed slightly more elegantly using
them.  Unfortunately n+k doesn't match against negative numbers, so

let n+1 = ... in .... n ...

is not the same as 

let n = .... in   .... (n-1) ...

Of course n+k was designed for natural numbers but these are not a
separate numeric type so you get a certain amount of confusion.  One
proposal was to make naturals a distinct type and restrict n+k to only

The syntactic issues surrounding n+k are truely awful and I still have
to look at the report to remember what happens with these:

n+1 = 2
(n+1) = 2

A lot of people would have been happy to replace n+k by some view-like
mechanism that gives the user control over the meaning of n+k but we
never managed to get views into the report.

More information about the Haskell-Cafe mailing list