Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
    • Locked Files
  • Issues 3,247
    • Issues 3,247
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 102
    • Merge Requests 102
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9334

Closed
Open
Opened Jul 19, 2014 by Iavor S. Diatchki@yav
  • Report abuse
  • New issue
Report abuse New issue

Implement "instance chains"

It would be useful to implement a version of "instance chains" [1] in GHC, which would eliminate the need for OVERLAPPING_INSTANCES in most (all practcial?) programs.

The idea is that programmers can explicitly group and order instances into an "instance chain". For example:

instance (Monad m)                  => StateM (StateT s m) s where ...
else     (MonadTrans t, StateM m s) => StateM (t m)        s where ... 

When GHC searches for instances, the instances in a chain are considered together and in order, starting with the first one:

  1. If the goal matches the current instance's head, then this instance is selected and the rest are ignored, as if they were not there;
  2. If the goal does not match the current instance's head, AND it does not unify with the current instance's head, then we skip the instance and proceed to the next member of the chain;
  3. If the goal does not match the current instance's head, but it does unify with it, then we cannot use this chain to solve the goal.

In summary: earlier instances in a chain "hide" later instances, and later instances can be reached only if we are sure that none of the previous instance will match.

[1] http://web.cecs.pdx.edu/\~mpj/pubs/instancechains.pdf

Trac metadata
Trac field Value
Version 7.9
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture

Related issues

Assignee
Assign to
Epic
None
Milestone
None
Assign milestone
Time tracking
None
Due date
No due date
3
Labels
feature request Trac import typechecker
Assign labels
  • View project labels
Reference: ghc/ghc#9334