[Haskell-cafe] What is a "simple pattern binding"?

dm-list-haskell-cafe at scs.stanford.edu dm-list-haskell-cafe at scs.stanford.edu
Sat Jun 25 16:52:13 CEST 2011

Section of the 2010 Haskell report says:

	A simple pattern binding has form p = e. The pattern p is
	matched “lazily” as an irrefutable pattern, as if there were
	an implicit ~ in front of it.

This makes it sound as though p is a pattern, which I assume means
what section 3.17 defines as the non-terminal "pat".

	pat -> lpat qconop pat | lpat

This is further suggested by the explicit mention of ~, which would be
redundant if p had to be a var, since variables always match
(according to section 3.17.2 rule 1).  So my reading of section is that the following is considered a simple pattern binding
(because it has no guards):

	(f, g) = (\x -> x, f)

However, section 4.5.5 seems to contradict this.  It reads:

	Recall that a variable is bound by either a function binding
	or a pattern binding, and that a simple pattern binding is a
	pattern binding in which the pattern consists of only a single
	variable (Section 4.4.3).

Moreover, it goes on to give an example and explanation:

        [(n,s)] = reads t
        ... Hence, when non-simple pattern bindings are used

This text makes it sound as though a "simple pattern binding" can have
only a single variable to the left of the = sign, meaning:

        f = \x -> x

Further confusing things, GHC accepts the following:

	g1 x y z = if x>y then show x ++ show z else g2 y x

	g2 :: (Show a, Ord a) => a -> a -> String
	g2 | False     = \p q -> g1 q p ()
	   | otherwise = \p q -> g1 q p 'a'
           where x = True

and infers type:

	g1 :: (Show a, Show a1, Ord a1) => a1 -> a1 -> a -> [Char]

According to, g2 definitely does not have a simple pattern
binding, as its binding is not of the form p = e where p is a pattern.
Yet by section 4.5.5, if g2 were not considered a simple pattern
binding, the constrained type variables in the binding group
containing g1 and g2 (in particular the inferred type (Show a => a) of
z in g1) would not be allowed to be generalized.

So is section of the Haskell 2010 report just wrong?  Or is
GHC allowing code prohibited by the standard?  Or am I somehow
misreading the standard?

Anyway, if someone can provide a less ambiguous definition of the term
"simple pattern binding", I would appreciated it, particularly if you
can point to support for your definition in the Haskell 2010 report...


More information about the Haskell-Cafe mailing list