Skip to content

Consistent pretty-printing of type families

Say I have this silly open type family declaration:

type family F a
type instance F a = a
type instance F a = Int

GHC complains:

Foo.hs:8:15: error:
    Conflicting family instance declarations:
      F a -- Defined at Foo.hs:8:15
      F a -- Defined at Foo.hs:9:15

Now let's do some silliness with a closed type family:

type family F a where
    F a = a
    F a = Int

GHC warns:

T6018.hs:9:5: warning:
    Type family instance equation is overlapped:
      F a = Int

Finally, some silliness with a kind-polymorphic type family:

type family Gc (a :: k) (b :: k) = r | r -> k where
    Gc a b = Int

GHC complains:

T6018.hs:9:5: error:
    Type family equation violates injectivity annotation.
    Injective kind variable ‘k’ is not inferable from the RHS type variables.
    In the RHS of type family equation:
    forall (k :: BOX) (a :: k) (b :: k). Gc a b = Int
    In the equations for closed type family ‘Gc’
    In the type family declaration for ‘Gc’

There are some inconsistencies in pprinting of type family equations:

  • for open type families we print the location where the equation was defined but we do not print the RHS
  • for closed type families we print the RHS but we do not print the location in the source file
  • kind-polymorphic equations are not indented

I would like to have a consistent pretty-printing of type family equations, one that prints the RHS, source code location and indents kind-polymorphic equations. The difference in pretty printing between open and closed type families comes from the difference between pprinting CoAxBranch and FamInst.

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