Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • 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,844
    • Issues 4,844
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 453
    • Merge requests 453
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18101

Closed
Open
Created Apr 26, 2020 by Xia Li-yao@LysxiaContributor

DeriveGeneric gets a wrong infix constructor associativity when type is declared in a different module

Summary

For example, the operators (:|) (NonEmpty) and (:) (lists, []) are infixr 5, but their Generic.Rep say otherwise ('InfixI 'LeftAssociative 9) (see code block below for an illustration).

My most plausible hypothesis for the cause is that DeriveGeneric does not take precedence into account when the type lives in a different module from its Generic instance. Indeed, NonEmpty and [] have their Generic instances derived in GHC.Generic, whereas things looks fine if we declare a type with an infix constructor and derive Generic in the same module.

ghci> :kind! (Rep [Int])
(Rep [Int]) :: * -> *
= D1
    ('MetaData "[]" "GHC.Types" "ghc-prim" 'False)
    (C1 ('MetaCons "[]" 'PrefixI 'False) U1
     :+: C1
           ('MetaCons ":" ('InfixI 'LeftAssociative 9) 'False)
      ...)

ghci> :kind! (Rep (NonEmpty Int))
(Rep (NonEmpty Int)) :: * -> *
= D1
    ('MetaData "NonEmpty" "GHC.Base" "base" 'False)
    (C1
       ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False)
       ...)

Expected behavior

These two examples should read 'InfixI 'RightAssociative 5.

Environment

  • GHC version used: 8.6, 8.8
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking