
On Saturday 21 May 2011 16:17:53, Paolo G. Giarrusso wrote:
As I said, I'm convinced that the argument of let is a pattern, on which a signature is allowed, and GHC correctly understands that, so that this declaration work: let (id :: Int -> Int) = \x -> x
I don't think that Prelude> let a :: a -> a = a a (or even Prelude> let id2 :: t -> t = \x -> x ) is supposed to work: "The pattern in a pattern binding may only mention type variables that are already in scope." Both are pattern bindings and the mentioned type variable is not in scope.
See both of: http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/other-type-extens ions.html#pattern-type-sigs http://www.haskell.org/onlinereport/decls.html#sect4.4.3.2
This is the expected use for such thing:
Prelude> :s -XScopedTypeVariables Prelude> let id2 :: forall t. t -> t; id2 (x :: t) = x
Why does then the following declaration work? let (id :: Int -> Int) = \x -> x
Because it doesn't mention any type variable.
To me, this inconsistent behavior is a bug, and surely it is undesirable, because of inconsistency - the programmer needs to have sensible rules, about when let var : type = expr works and when not. Or at least a sensible error message.
The error message definitely deserves improvement.