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,861
    • Issues 4,861
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • 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
  • #21416
Closed
Open
Created Apr 22, 2022 by Adam Gundry@adamgundryDeveloper

Extra-constraints wildcards in instance declarations

Extra-constraints wildcards are sometimes handy for figuring out the constraints to put on a function definition. However, they cannot be used in instance declarations:

GHCi, version 9.2.2: https://www.haskell.org/ghc/  :? for help
ghci> let { foo :: _ => a -> String ; foo = show }

<interactive>:1:14: error:
    • Found extra-constraints wildcard standing for ‘Show a’
      Where: ‘a’ is a rigid type variable bound by
               the inferred type of foo :: Show a => a -> String
               at <interactive>:1:7-29
      To use the inferred type, enable PartialTypeSignatures
    • In the type signature: foo :: _ => a -> String
ghci> data I a = I a
ghci> instance _ => Show (I a) where show (I x) = show x

<interactive>:3:10: error:
    Wildcard ‘_’ not allowed
      in an instance declaration

Is there a fundamental reason for this restriction? It seems to me that it should be possible to infer the extra constraints required by an instance, just as GHC already does for functions (though I can imagine the implementation might be slightly less trivial because it would need to gather the wanted constraints from all the methods, then simplify them).

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking