Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,926
    • Issues 4,926
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 462
    • Merge requests 462
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #13680
Closed
Open
Created May 10, 2017 by Ryan Scott@RyanGlScottMaintainer

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 Mar 10, 2019 by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking