[Haskell-cafe] What is a "simple pattern binding"?
Scott Turner
2haskell at pkturner.org
Sat Jun 25 20:20:52 CEST 2011
On 2011-06-25 10:52, David Mazieres wrote:
> 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 4.4.3.2, 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.
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".
More information about the Haskell-Cafe
mailing list