Skip to content

Inconsistent warning message involving type families

Summary

Apologies if this has been discussed before. The following code doesn't type check:

{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE TypeFamilies #-}

type family F a

foo :: F a -> Int
foo _ = 42

bar :: F a -> Int
bar = foo

The error is

    * Couldn't match type `F a' with `F a0'
      Expected type: F a -> Int
        Actual type: F a0 -> Int
      NB: `F' is a non-injective type family
      The type variable `a0' is ambiguous
    * In the expression: foo
      In an equation for `bar': bar = foo
    * Relevant bindings include
        bar :: F a -> Int (bound at Foo.hs:10:1)
   |
10 | bar = foo

It type checks if I remove the type signature of bar, but it warns that

Top-level binding with no type signature: bar :: F a -> Int

which is exactly what the type signature is.

Expected behavior

I don't know if the above code is supposed to type check or not (I don't see a reason why not, but I could be wrong). If it is not supposed to type check, the warning message upon removing the type signature of bar could be made less confusing.

Environment

  • GHC version used: 8.8.1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information