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,872
    • Issues 4,872
    • 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
  • #20358
Closed
Open
Created Sep 11, 2021 by sheaf@sheafMaintainer

Allow "instances" for non-typeclass constraints in signature files

The contiguous library defines a typeclass for primitive arrays, with an associated constraint:

type Contiguous :: ( Type -> Type ) -> Constraint
class Contiguous arr where
  type Element arr :: Type -> Constraint
  -- ... array methods

Now, with backpack one might want to declare:

  • an array type that is an instance of Contiguous,
  • a key type which is an allowed element of the array.

Specifically:

data Key
data Array k
instance Contiguous Array
instance Element Array Key

This currently isn't allowed:

    * Illegal instance for a associated type family
      A class instance must be for a class
    * In the instance declaration for `Element Array Key'
   |
   | instance Element Array Key
   |          ^^^^^^^^^^^^^^^^^

However I think it would make sense to allow this; I don't think there's any other available mechanism to specify that any instantiation of Key and Array should satisfy the additional constraint Element Array Key. Of course it's not strictly an instance (as Element is not a typeclass, but a constraint synonym), but the alternative would be to invent backpack-specific syntax.

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