Skip to content

Wrong error message for type family definition that is wrong in multiple ways

GHCi, version 8.1.20160212: http://www.haskell.org/ghc/  :? for help
Prelude> :set -XTypeFamilies
Prelude> type family T where { Maybe T = Int }

<interactive>:2:23: error:
    • Too many parameters to T:
        T is unexpected;
        expected only no parameters
    • In the type family declaration for ‘T’

This error message is wrong ("Too many parameters to T").

Seems like GHC checks whether the equation Maybe T = Int has the right number of arguments before it checks whether it is actually headed by T. Then the error message is worded in a way that assumes the instance head actually was T.

The 7.10 error message was better in this regard:

<interactive>:3:23:
    Number of parameters must match family declaration; expected 0
    In the type family declaration for ‘T’

but it would be even better to generate the error below (that is generated once the number of arguments is correct) for the original program:

Prelude> type family T a where { Maybe (T ()) = Int }

<interactive>:5:25: error:
    • Mismatched type name in type family instance.
        Expected: T
          Actual: Maybe
    • In the type family declaration for ‘T’

We should generate that error before kind-checking the definition too.

I don't really understand the difference between these two cases though, so maybe my guess is wrong.

Prelude> type family T where { T () = Int }

<interactive>:10:23: error:
    • Too many parameters to T:
        () is unexpected;
        expected only no parameters
    • In the type family declaration for ‘T’
Prelude> type family T :: * -> * where { T () = Int }

<interactive>:11:33: error:
    • Number of parameters must match family declaration; expected 0
    • In the equations for closed type family ‘T’
      In the type family declaration for ‘T’

(As an aside, "expected only no parameters" is awkward, if there is some legitimate way to generate this message. It should just be "expected no parameters".)

Trac metadata
Trac field Value
Version 8.1
Type Bug
TypeOfFailure OtherFailure
Priority low
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