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

dm-list-haskell-cafe at scs.stanford.edu dm-list-haskell-cafe at scs.stanford.edu
Sun Jun 26 00:52:49 CEST 2011

At Sat, 25 Jun 2011 14:20:52 -0400,
Scott Turner wrote:
> > 	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.
> I agree that the report is confusing in its use of "simple pattern binding".

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?

In fact, section 4.5.2 goes on to use the following example for a
declaration group:

	  f x = let g1 x y = if x>y then show x else g2 y x  
		    g2 p q = g1 q p  
		in ...

This example is very close to the code I gave.  How can my example
have two declaration groups when this example has only one?


More information about the Haskell-Cafe mailing list