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

Paterson, Ross R.Paterson at city.ac.uk
Sun Jun 26 01:17:12 CEST 2011

> > >     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
> >
> > It appears to me that GHC is justified. According to 4.5.1 and 4.5.2, g1
> > by itself constitutes a declaration group. It is considered by itself
> > and is generalized prior to combining it with g2.

> Great, now I'm even more confused.  4.5.1 says:

>         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

>          2. b1 depends on a binding that depends on b2.

>         A declaration group is a minimal set of mutually dependent
>         bindings. Hindley-Milner type inference is applied to each
>         declaration group in dependency order.

> So here the first binding (of g1) contains the free identifier g2,
> which is bound by the second binding.  Conversely, the second binding
> contains g1 free.  So the two bindings are mutually dependent, no?

No, the binding of g1 doesn't depend on the binding of g2, because g2
has a type signature (clause 1).

The type of g1 is inferred using the declared type of g2.  Then that
type is used in inferring a type for g2, which will be compared with
its declared signature.

More information about the Haskell-Cafe mailing list