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

Sun Jun 26 08:46:08 CEST 2011

```At Sun, 26 Jun 2011 01:41:01 +0100,
Paterson, Ross wrote:
>
> > I thought "no type signature" meant no type signature inside b1.
>
> No, it means no type signature for the variable.
>
> > Otherwise, you are saying nothing could depend on a binding with a
> > type signature.  By that logic, there can be no mutual dependence,
> > and so every declaration with a type signature is its own (singleton)
> > declaration group.
>
> A pattern binding can bind more than one variable.  If all the variables
> bound by a binding have type signatures, that binding is indeed a
> singleton declaration group.

If this is the case, then multiple sentences in the 2010 report don't
make sense, though the way in which they don't make sense sort of
depends on what "simple pattern binding" means.  Which of the
following constitute a simple pattern binding?

a.  a | False     = undefined
| otherwise = \x -> x

b.  Just b = Just (\x -> x)

c.  Just c | False     = undefined
| otherwise = Just (\x -> x)

d.  (d, d') = (\x -> x, d)

e.  (e, e') | False     = undefined
| otherwise = (\x -> x, e)

If it's any clue, GHC infers a polymorphic type for a only.  It infers
type "GHC.Prim.Any -> GHC.Prim.Any" for the others.  Moreover, GHC
accepts the type signature "a :: t -> t", but rejects such a
polymorphic signature for the other variables, and also rejects
programs such as:

Just b = Just (\x -> x)

f :: (Show a) => a -> a
f = b                     -- illegal

So let's work under the assumption that a is a simple pattern binding,
and the others are not.  If you have a different definition, I'll make
a different argument.  (Note also that if you agree with this
definition, then there is a bug in section 4.4.3.2 of the report,
since a is not of the form "p = e".  But if you take the 4.4.3.2
definition, then I'll argue section 4.5.5 has a bug.)

Let's posit a definition that accepts only a (and in particular that
rejects d and e).  Such a definition is further supported by the
phrase "a simple pattern binding is a pattern binding in which the
pattern consists of only a single variable" (from section 4.5.5).

If we accept that a simple pattern binding cannot bind more than one
variable, then the definition of the monomorphism restriction in
section 4.5.5 is not consistent with your interpretation of the term
declaration group.  After all, given our posited definition, the
following language in 4.5.5:

(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.

(a): every binding is a function binding, or

(b): the group consists of a simple pattern binding with an
explicit type signature.

In particular, why would the report say "an explicit type signature is
given for EVERY variable" when there can be only one such variable?

David

```