Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,260
    • Issues 4,260
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 402
    • Merge Requests 402
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8161

Closed
Open
Opened Aug 23, 2013 by Adam Gundry@adamgundryDeveloper

Associated type parameters that are more specific than the instance header

It would be nice if type parameters of associated types could be more specific than those in the instance header. This is currently rejected with the message "Type indexes must match class instance head", but could be accepted:

{-# LANGUAGE TypeFamilies #-}

class C a where
  type T a

instance C [a] where
  type T [Bool] = Int
  type T [Int]  = Int

More typically, this is useful where we want to use an equality constraint to make type inference easier, but need to match on the actual type in an associated type:

{-# LANGUAGE TypeFamilies, FlexibleInstances #-}

class C a where
  type T a

instance a ~ [b] => C a where
  type T [b] = Int

This showed up in the implementation of OverloadedRecordFields. Of course, one can always work around it using a normal (non-associated) type family.

Note that we already allow type families to specialise variables that do not occur in the instance header:

{-# LANGUAGE TypeFamilies #-}

class C a where
  type T a b

instance C [a] where
  type T [a] [Bool] = Bool
  type T [a] [Int]  = Int
Trac metadata
Trac field Value
Version 7.7
Type FeatureRequest
TypeOfFailure OtherFailure
Priority low
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#8161