Skip to content

GHC thinks type variables are not bound by data family constructor in LHS of type synonym instance

Summary

Today I tried building GHC HEAD for the first time, so disclaimer: this could be user error. But assuming it isn’t, I seem to be getting an error on this fairly benign program:

{-# LANGUAGE TypeFamilies #-}
module DataFamilySynonymInstance where
data family D a
type family F a
type instance F (D a) = a
$ ghc DataFamilySynonymInstance.hs
[1 of 1] Compiling DataFamilySynonymInstance ( DataFamilySynonymInstance.hs, DataFamilySynonymInstance.o )

DataFamilySynonymInstance.hs:5:20: error:
    • Type variable ‘a’ is mentioned in the RHS,
        but not bound on the LHS of the family instance
        The real LHS (expanding synonyms) is: F (D a)
    • In the type instance declaration for ‘F’
  |
5 | type instance F (D a) = a
  |                    ^

GHC 8.6.5 accepts this program, as I am fairly certain it ought to.

Environment

  • GHC version used: 8.9.0.20190816 (built with Hadrian --flavour=prof)
  • Operating System: macOS 10.14.5
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information