Skip to content

Can't call rank-2 function with type family constraint

The following code compiles with 7.10.3:

newtype Bar r = Pow r deriving (Eq)
instance (Foo r) => Foo (Bar r)

type family Ctx a where Ctx t = (Foo (Bar t), Eq (Bar t))

run :: (forall t . (Ctx t) => t -> Int) -> Int
run g = undefined

foo :: (Foo (Bar t)) => t -> Int
foo = undefined

main :: IO ()
main = print $ run foo

but fails in 8.0.1 with

    • Could not deduce (Foo t) arising from a use of ‘foo’
      from the context: Ctx t
        bound by a type expected by the context:
                   Ctx t => t -> Int
        at Main.hs:19:16-22
      Possible fix:
        add (Foo t) to the context of
          a type expected by the context:
            Ctx t => t -> Int
    • In the first argument of ‘run’, namely ‘foo’
      In the second argument of ‘($)’, namely ‘run foo’
      In the expression: print $ run foo

This code seems valid to me: when I call run foo, foo is specialized to (Foo (Bar t), Eq (Bar t)) => t -> Int), which meets the requirement of the argument to run.

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