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,865
    • Issues 4,865
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • 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
  • #20113
Closed
Open
Created Jul 14, 2021 by sheaf@sheafMaintainer

Should we allow a newtype with a representation-polymorphic field with NoFieldSelectors?

The following newtype declaration is accepted:

{-# LANGUAGE PolyKinds, UnliftedNewtypes#-}
import GHC.Exts

newtype X (a :: TYPE rep) = MkX a

However, the following is rejected:

{-# LANGUAGE PolyKinds, UnliftedNewtypes, NoFieldSelectors #-}
import GHC.Exts

newtype Y (a :: TYPE rep) = MkY { y_fld :: a }
    A representation-polymorphic type is not allowed here:
      Type: a
      Kind: TYPE rep
    In the type of binder `$sel:y_fld:MkY'
  |
4 | newtype Y (a :: TYPE rep) = MkY { y_fld :: a }
  |                                   ^^^^^

The problem is that the field selector is still generated internally (whence the mangled selector name $sel:y_fld:MkY leaking out into the error message), which runs into trouble with the representation polymorphism checks.
I'm not sure exactly what to do. We could continue to reject the program (possibly improving the error message); we could not generate the field selector at all; or we could somehow attempt to generate a representation polymorphic selector which must be representation-monomorphic at use-sites.

cc-ing @adamgundry and @simonpj for thoughts.

Edited Jul 14, 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