Proposal: fix "simple pattern binding" and "declaration group"

dm-list-haskell-prime at scs.stanford.edu dm-list-haskell-prime at scs.stanford.edu
Sun Jun 26 20:57:01 CEST 2011


The Haskell 2010 report contains ambiguous and sometimes contradictory
definitions of the terms "simple pattern binding" and "declaration
group".	 The confusion is compounded by the phrasing of the
monomorphism restriction, which is carried over from the Haskell98
report in which a different definition of declaration group required a
more complicated description of the monomorphism restriction.

A recent thread on the haskell cafe mailing list summarizes the
problem:

	http://www.haskell.org/pipermail/haskell-cafe/2011-June/093488.html

To resolve this confusion, I propose applying the following changes to
the Haskell 2010 report for the next revision of the language:

In section "4.4.3.2 Pattern bindings", replace:

-	A pattern binding binds variables to values. 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. See the translation in Section 3.12.

With the following:

	A pattern binding binds variables to values.  A /simple/
	pattern binding is one in which the pattern consists of a
	single variable, yielding a declaration of the form /var/
	/rhs/.  Recall from section 3.17 that such a pattern is always
	irrefutable.

In section 4.5.1, replace this text:

-	A binding b1 depends on a binding b2 in the same list of
-	declarations if either
-
-	1. b1 contains a free identifier that has no type signature
-	   and is bound by b2, or

with the following:

	A binding b1 depends on a binding b2 in the same list of
	declarations if either

	1. b1 contains a free identifier v, v is bound by b2, and the
	   list of declarations does not contain a type signature for
	   v; or

Add the following text to the end of section 4.5.1:

	For example, the following two bindings form a single
	declaration group, as each contains a free identifier bound by
	the other and, despite the presence of expression
	type-signatures, the declaration list contains no type
	signatures:

	(x, y) = (z :: Int, 1 :: Int)  -- binds y, has z free
	(z, t) = (2 :: Int, y :: Int)  -- binds z, has y free

	Conversely, the following two bindings constitute two
	different declaration groups.  Even though f and g contain
	each other as free identifiers, the declaration list contains
	a type signature for f, so g does not depend on f.

	f :: (Eq a) => (a, a) -> (Bool, a)
	f = \(x, y) -> (x == y, snd (g (x, y)))
	g pair = (fst (f pair), snd pair)

	Note that if b is a function binding or simple pattern binding
	and b is accompanied by a type signature, then b always
	constitutes a /singleton/ declaration group, regardless of
	what free identifiers it contains.  (If b is a non-simple
	pattern binding, it may bind multiple variables
	simultaneously.)

Finally, change Rule 1 of the monomorphism restriction in section
4.5.5, by replacing the following text:

-	We say that a given declaration group is unrestricted if and
-	only if:
-
-	(a): every variable in the group is bound by a function
-	     binding or a simple pattern binding (Section 4.4.3.2),
-	     and
-
-	(b): an explicit type signature is given for every variable in
-	     the group that is bound by simple pattern binding.

with the following:

	We say that a given declaration group is unrestricted if and
	only if:

	(a): every variable in the group is bound by a function
	     binding, or

	(b): the group consists of exactly one binding, the binding is
	     a simple pattern binding of some variable v, and the
	     binding's declaration list contains an explicit type
	     signature for v.

If there is agreement on these changes or something along these lines,
I can create a ticket and/or wiki page.  I propose the name
SimplePatternBinding for the change.

David



More information about the Haskell-prime mailing list