typechecking too eager?
andres at cs.uu.nl
Sun Nov 7 14:15:44 EST 2004
> The following code should compile (If the constructor
> is valid, so is the function):
> data Test = Test (forall a . a)
> test a = Test a
> However this fails to compile with the following error:
The current implementation of rank-n polymorphism
(which is documented in the paper "Pratical type inference
for arbitrary-rank types") does not "guess" polymorphic
types for lambda-abstracted values.
In this situation, this means that the variable "a"
is assumed to have a monorphic type, which then cannot
be passed to "Test" as an argument.
Knowledge about polymorphism is passed down/inwards,
but not up/outwards.
This definition typechecks only if you add a type
test :: (forall a . a) -> Test
If you want to know the reasons, read the paper. It explains
the problems very well.
More information about the Glasgow-haskell-users