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,393
    • Issues 4,393
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 378
    • Merge Requests 378
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #13443

Closed
Open
Opened Mar 18, 2017 by tomjaguarpaw@trac-tomjaguarpaw

Typeclass resolution errors quite puzzling

This ticket is based on a post I made to haskell-cafe: https://mail.haskell.org/pipermail/haskell-cafe/2016-August/124622.html

Here's a program with an odd error message (GHC 8.0.1):

    data A a = A a deriving Eq
    data B = B
    
    main :: IO ()
    main = print (A B == A B)

    test/main.hs:5:15: error:
        • No instance for (Eq B) arising from a use of ‘==’
        • In the first argument of ‘print’, namely ‘(A B == A B)’
          In the expression: print (A B == A B)
          In an equation for ‘main’: main = print (A B == A B)

I get an error about Eq B even though it's Eq A that is manifestly required at the call site. This error is odder when A and B are defined far away from the use of ==.

This is even odder:

    data A a = A a
    data B = B
    
    instance Ord a => Eq (A a) where
    
    main :: IO ()
    main = print (A B == A B)
    
    test/main.hs:7:15: error:
        • No instance for (Ord B) arising from a use of ‘==’
        • In the first argument of ‘print’, namely ‘(A B == A B)’
          In the expression: print (A B == A B)
          In an equation for ‘main’: main = print (A B == A B)

Now not only is the type puzzling (B instead of A) but the *class* is puzzling (Ord instead of Eq). This occurred to me in practice because Data.Graph.Inductive.PatriciaTree.Gr has (Eq a, Ord b) => Eq (Gr a b).

It would have been a lot more helpful to see

    * No instance for (Ord B)
        * arising from (Eq A)
        * arising from the use of '=='

Does anyone agree with me that GHC should produce the full trace when it fails to resolve instances rather than just the proximal failure?

Edited Mar 10, 2019 by Ben Gamari
Assignee
Assign to
8.6.1
Milestone
8.6.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#13443