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,862
    • Issues 4,862
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 455
    • Merge requests 455
  • 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
  • #21324
Closed
Open
Created Mar 31, 2022 by Ollie Charles@ocharles

HasField instances cannot be defined on newtypes that have a field selector even if that isn't exported

Motivation

I would like to able to provide a HasField instance for reactive-banana Behaviors. Specifically, I want to write

instance HasField x a b => HasField (x :: Symbol) (Behavior a) (Behavior b) where
  getField behavior = behavior <&> getField @x

Unfortunately, GHC refuses to allow me to write this, reporting:

lib/Reactive/Banana/Orphans.hs:36:28: error:
    • Illegal instance declaration for
        ‘HasField x (Behavior a) (Behavior b)’
        Behavior has fields
    • In the instance declaration for
        ‘HasField (x :: Symbol) (Behavior a) (Behavior b)’
   |
36 | instance HasField x a b => HasField (x :: Symbol) (Behavior a) (Behavior b) where
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

but I disagree that Behavior has fields. Internally Behavior is defined as

newtype Behavior a = B { unB :: Prim.Behavior a }

but that is never exported - no module expect the defining one can see that field.

Proposal

I am able to write the instance.

Edited Mar 31, 2022 by Ollie Charles
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking