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,273
    • Issues 4,273
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 413
    • Merge Requests 413
  • 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
  • #15974

Closed
Open
Opened Nov 29, 2018 by Alexis King@lexi.lambda

QuantifiedConstraints: Spurious error involving superclass constraints

{-# LANGUAGE KindSignatures, QuantifiedConstraints, UndecidableInstances #-}

Consider the following datatype and two classes:

data X (f :: * -> *)

class A a
class A a => B a

If I create an instance A (X f) involving a quantified constraint

instance (forall a. A a => A (f a)) => A (X f)

then curiously, the following instance declaration for B (X f) is rejected with the accompanying error message:

instance (forall a. B a => B (f a)) => B (X f)
/tmp/qc.hs:11:10: error:
    • Could not deduce (B a)
        arising from the superclasses of an instance declaration
      from the context: forall a. B a => B (f a)
        bound by the instance declaration at /tmp/qc.hs:11:10-46
      or from: A a bound by a quantified context at /tmp/qc.hs:1:1
      Possible fix: add (B a) to the context of a quantified context
    • In the instance declaration for ‘B (X f)’
   |
11 | instance (forall a. B a => B (f a)) => B (X f)
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Notably, if the instance declaration for A (X f) is altered to not use a quantified constraint, as in

instance A (f (X f)) => A (X f)

or even just

instance A (X f)

then the above instance declaration for B (X f) is accepted.

I see no reason that the B (X f) declaration should be rejected, even with the quantified constraint in the instance context for A (X f). The error message complains that the typechecker cannot deduce B a, and it even suggests adding B a to the context of the quantified constraint, but B a is //already// in that context.

Trac metadata
Trac field Value
Version 8.6.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
8.6.3
Milestone
8.6.3
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#15974