GHC instantiates levity-polymorphic type variables with foralls
Consider the following use of error.
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 error and 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.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | goldfire, simonpj |
| Operating system | |
| Architecture |