Misleading error in boot file when superclass constraint is present but methods are absent
Summary
In boot files, when superclass constraint is present but class methods are omitted, the error message talks about incompatible method count and MINIMAL pragmas.
I think when the keyword where
and the methods are omitted in the class
declaration in the boot file, GHC should assume that the user chose not to repeat the methods in the boot file, rather than complaining.
If it is mandatory to omit the superclass constraints always when the methods are omitted, GHC should give the user a hint in the error message, like "Class methods can only be omitted when superclass constraints are omitted as well".
Steps to reproduce
module A where
import B
class Eq a => Diag a where
diag :: a -> Bool
instance Diag Int where
diag = bar
module B where
import {-# SOURCE #-} A
bar :: Diag a => a -> Bool
bar = undefined
Boot file A.hs-boot
:
module A where
-- class Diag a -- WORKS
class Eq a => Diag a
-- A.hs-boot:5:1: error:
-- Class ‘Diag’ has conflicting definitions in the module
-- and its hs-boot file
-- Main module: class Eq a => Diag a where
-- diag :: a -> Bool
-- {-# MINIMAL diag #-}
-- Boot file: class Eq a => Diag a
-- The methods do not match: There are different numbers of methods
-- The MINIMAL pragmas are not compatible
Expected behavior
Better error message:
- Don't complain about MINIMAL pragmas that the user has not written.
- Don't complain about different number of methods.
- Rather complain (if necessary) about superfluous superclass constraints.
Conceptually, it is unclear to me why the superclass constraints absolutely must be omitted when the methods are omitted. What is the harm of providing more than the minimal information?
The problem with the current behavior is that it leads the user towards adding more stuff into the boot file when the best solution is to put less stuff. (And you know, you only wanted the banana, but it was in the grip of an ape that held on to a tree whose roots where entangled with the roots of the other trees of the rainforest... :D)
Environment
- GHC version used: 8.8.1