Skip to content

Indicate missing associated type instances

If there is no matching instance for a typeclass that defines an associated type, GHC cannot further reduce an application of that associated type. For nested type family applications, this produces rather large error messages, eg:

<interactive>:98:20:
    Couldn't match type ‘units-2.3:Data.Metrology.Factor.Normalize
                           (Data.Metrology.Suspicious.Poly.SurfaceUnitFactorsOf
                              (Data.Singletons.Prelude.Tuple.Snd
                                 (Data.Metrology.Suspicious.Poly.SplitPrefix
                                    (PrefixExp Deci) Deci Core))
                            units-2.3:Data.Metrology.Factor.@- '['units-2.3:Data.Metrology.Factor.F
                                                                   Core
                                                                   ('Data.Metrology.Z.S
                                                                      'Data.Metrology.Z.Zero)])’
                   with ‘'[]’
    In the expression: (25 %> centi Core) `ceilToUnit` deci Core
    In an equation for ‘it’:
        it = (25 %> centi Core) `ceilToUnit` deci Core

The cause of the above error message is that Deci is not a member of the typeclass ExpUnitPrefix that defines the associated type PrefixExp. Unfortunately this is not clear at all from the error message, and adding additional class constraints to the appropriate functions doesn't improve things.

It would be nice if GHC pointed out that there is no ExpUnitPrefix Deci instance, or at least that PrefixExp Deci cannot be further reduced. I imagine this would be useful for open type families as well, but I can't comment personally.

Trac metadata
Trac field Value
Version 7.10.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information