Consider this example from a GHCi session:
Prelude> :set -XRankNTypes Prelude> let bar :: (forall a.[a]->[a]) -> [Int]; bar f = f [1,2,3]
This defines a bar function with a rank-2 type. Therefore, type inference should not infer the correct type for:
Prelude> let foo f = bar f
And indeed
<interactive>:7:17: Couldn't match type `t' with `[a] -> [a]' `t' is a rigid type variable bound by the inferred type of foo :: t -> [Int] at <interactive>:7:5 In the first argument of `bar', namely `f' In the expression: bar f In an equation for `foo': foo f = bar f
Surprisingly, if we write the same thing in a free style, this works:
Prelude> let baz = bar Prelude> :t baz baz :: (forall a. [a] -> [a]) -> [Int]
How is it that type inference can infer a higher rank type here? Can someone confirm that this is specifically addressed in the GHC, or indicate where I am mistaken.
source share