Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 637
    • Merge requests 637
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • 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 CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19154

GHC 9.0 no longer typechecks a program involving overloaded labels and type applications

In the program that follows, I specify the type of a label by using a visible type application.

{-# LANGUAGE DataKinds              #-}
{-# LANGUAGE FlexibleInstances      #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE OverloadedLabels       #-}
{-# LANGUAGE PolyKinds              #-}
{-# LANGUAGE RebindableSyntax       #-}
{-# LANGUAGE ScopedTypeVariables    #-}
{-# LANGUAGE TypeApplications       #-}

module Labels where

-- base
import Prelude
import Data.Kind
  ( Type )
import GHC.TypeLits
  ( Symbol, KnownSymbol )

--------------------------------------------------------------------------

data Label (k :: Symbol) (a :: Type) = Label

class IsLabel k a v | v -> a, v -> k where
  fromLabel :: v

instance KnownSymbol k => IsLabel k a (Label k a) where
  fromLabel = Label @k @a

foo :: Label k a -> ()
foo _ = ()

test :: ()
test = foo ( #label @Bool )

The point of this program is that the label #label is polymorphic:

#label :: forall (a :: Type). Label "label" a

and I am able to instantiate the type variable a with a type application.

Show/hide further context. This was boiled down from the overloaded label syntax I provide in my shader library, see here.

This added bit of syntax allows users of the library to write shaders in an imperative style, see here for an example.

This program compiles fine on GHC 8.10 (and previous GHC versions), but fails to compile on GHC 9.0 (rc1) with the following error:

Labels.hs:35:14: error:
    * Cannot apply expression of type `v0'
      to a visible type argument `Bool'
    * In the first argument of `foo', namely `(#label @Bool)'
      In the expression: foo (#label @Bool)
      In an equation for `test': test = foo (#label @Bool)
   |
35 | test = foo ( #label @Bool )
   |              ^^^^^

Can someone enlighten me about what's going on? I found it quite useful to be able to pass further arguments to an overloaded label in this way, whereas I now have to write something like

test :: ()
test = foo ( #label :: Label _ Bool )

to specify a, which defeats the purpose of the overloaded labels syntax. At that point I might as well just write:

foo ( Label @"label" @Bool )
Edited Jan 02, 2021 by sheaf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking