Skip to content

Functional dependencies not propagated by type applications

Summary

In GHC 8.10.7 and 9.0.1, a type application to a typeclass method causes functional dependencies to be evaluated. GHC 9.2.1 no longer does this.

Steps to reproduce

Consider the following code Foo.hs:

{-# LANGUAGE DataKinds, FunctionalDependencies, UndecidableInstances #-}
import GHC.TypeLits

class C a b | a -> b where
  f :: a -> b

instance TypeError (Text "boom") => C Char Int where
  f = undefined

Attempt to determine the type of f @Char on GHC 9.2.1:

$ ghci
GHCi, version 9.2.1: https://www.haskell.org/ghc/  :? for help
ghci> :l Foo.hs 
[1 of 1] Compiling Main             ( Foo.hs, interpreted )
Ok, one module loaded.
ghci> :set -XTypeApplications 
ghci> :t f @Char
f @Char :: C Char b => Char -> b
ghci> 

Expected behavior

On GHC 8.10.7 and 9.0.1, this triggered the custom type error:

$ ghci
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
Prelude> :l Foo.hs 
[1 of 1] Compiling Main             ( Foo.hs, interpreted )
Ok, one module loaded.
*Main> :set -XTypeApplications 
*Main> :t f @Char

<interactive>:1:1: error: boom
*Main> 

Environment

  • GHC version used: 9.2.1

Optional:

  • Operating System: GNU/Linux
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information