I am trying to understand RankNTypes in Haskell and found this example:
check :: Eq b => (forall a. [a] -> b) -> [c] -> [d] -> Bool check f l1 l2 = f l1 == f l2
(If my understanding is correct, this is equivalent to check :: forall bc d. Eq b => (forall a. [a] -> b) -> [c] -> [d] -> Bool .)
Ok, so far so good. Now, if explicit forall a removed, the GHC generates the following errors:
Could not deduce (c ~ a) from the context (Eq b) [β¦] Could not deduce (d ~ a) from the context (Eq b) [β¦]
When deleting a nested forall type signature becomes
check :: forall abc d. Eq b => ([a] -> b) -> [c] -> [d] -> Bool
It is easy to see why this does not check type checking, since l1 and l2 must be of type [a] so that we can pass them to f , but why it is not, when f specified, enter (forall a. [a] ->b) ? Is the fact that a is connected only inside the parens complete answer? That is, type checking will take
[c] -> b ~ (forall a. [a] -> b) [d] -> b ~ (forall a. [a] -> b)
(edit: fixed thanks, Boyd!)
since a function like (forall a. a -> b) can accept any list?
types haskell
beta
source share