Can't use TypeApplications with [] data constructor
Why can't I do this?
{-# LANGUAGE TypeApplications #-}
module Bug where
foo :: [Int]
foo = [] @Int
Compiling this with GHC 8.0.1, 8.0.2, 8.2.1, or HEAD gives me:
$ /opt/ghc/head/bin/ghci Bug2.hs
GHCi, version 8.3.20170509: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug2.hs, interpreted )
Bug2.hs:5:7: error:
• Cannot apply expression of type ‘[a0]’
to a visible type argument ‘Int’
• In the expression: [] @Int
In an equation for ‘foo’: foo = [] @Int
|
5 | foo = [] @Int
| ^^^^^^^
This seems really strange, since I can use TypeApplications with expressions like Nothing @Int without issues. According to GHCi:
$ /opt/ghc/head/bin/ghci
GHCi, version 8.3.20170509: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
λ> :set -XTypeApplications -fprint-explicit-foralls
λ> :type +v []
[] :: forall {a}. [a]
λ> :type +v Nothing
Nothing :: forall a. Maybe a
The type variable for [] isn't visible! But I don't see any reason why it shouldn't be, especially since, conceptually, the data type declaration for lists is:
data [] a = [] | a : [a]
I suspect that []'s tyvar binder visibility is not wired into GHC correctly.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |
Edited by Ryan Scott