GHC instantiates levity-polymorphic type variables with foralls
Consider the following use of
ghci> :t error error :: forall (v :: GHC.Types.Levity) (a :: TYPE v). (?callStack::GHC.Stack.Types.CallStack) => [Char] -> a ghci> :t error "bad" :: (forall a. a -> a) -> a error "bad" :: (forall a. a -> a) -> a :: (?callStack::GHC.Stack.Types.CallStack) => (forall a1. a1 -> a1) -> a
GHC is instantiating the type variable
a in the output with
(forall a. a -> a) -> a, which requires impredicative polymorphism. So this example should actually be rejected by the type checker.
Note that GHC also does this with open-kinded type variables, so the behavior with
undefined has been around for a while. There are tests that depend on it, and a Note that describes the decision to accept these programs. Still, Simon PJ says perhaps we should really just reject these programs.
So here's a ticket to discuss the matter.
For more information, see the discussion starting at https://phabricator.haskell.org/D1739#51408.