Opened 21 months ago

Last modified 2 months ago

#10749 new bug

Boot file instances should imply superclasses

Reported by: ezyang Owned by: ezyang
Priority: normal Milestone:
Component: Compiler Version: 7.11
Keywords: backpack Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Currently, if I write the following program:

-- A.hs-boot
module A where
data T
instance Ord T

-- B.hs
module B where
import {-# SOURCE #-} A
f :: T -> T -> Bool
f x y = x == y 

I get:

    No instance for (Eq T) arising from a use of `=='
    Possible fix: add an instance declaration for (Eq T)
    In the expression: x == y
    In an equation for `f': f x y = x == y

This is a bit confusing, because Ord instances are supposed to imply Eq instances.

GHC should either:

  1. Reject A.hs-boot (claiming that it could not find evidence that T had an Eq instance), or
  2. Accept B.hs, since the instance requirement for Ord should imply Eq.

Change History (3)

comment:1 Changed 21 months ago by goldfire

I vote for (1). A.hs-boot is wrong.

comment:2 Changed 3 months ago by ezyang

Priority: lownormal

Something that I've noticed is that (1) is not consistent with how superclasses work. For example, if I say: Ord a => a -> a -> Bool, I DO get an Eq instance in scope (because Eq is a superclass of Ord). So in practice, when I'm writing instances for modules in Backpack, I end up having to list a lot of instances, e.g., Functor, Applicative, Monad, MonadFix, etc. when, in the source code I was looking at, there was only MonadFix. Food for thought.

comment:3 Changed 2 months ago by ezyang

I took a look into solving this, but I realized that I don't actually know how we normally report an error when an instance declaration is made but the superclasses do not hold. The error isn't reported until late when we're discharging top-level wanteds so I actually have no idea where the wanted is coming from (or why it's not coming in the case of hs-boot.)

Note: See TracTickets for help on using tickets.