If you want to use GHC's lexically scoped type variables, you also have to use explicit universal quantification. That is, you have to add forall
declarations to your functions' type signatures:
{-# LANGUAGE ExplicitForAll, ScopedTypeVariables #-}
f :: forall a . [a] -> [a] -- The `forall` is required here ...
f (x:xs) = xs ++ [x :: a] -- ... to relate this `a` to the ones above.
Does this actually have anything to do with quantification, or did the extension writers just coopt the forall
keyword as a convenient marker for where the new, wider scoping applies?
In other words, why can't we leave out the forall
as usual? Wouldn't it be clear that type variables in annotations within the function body refer to variables of the same name in the function signature? Or would the typing be somehow problematic or ambiguous?