Isn't this error message completely wrong? The error has nothing to do with
AApply
.
Not completely. It's arguably a bug that you get that error message, but it's not completely off base.
Look at the whole thing together after looking at the pieces.
test (APure) a = a
says we have a function
test :: A a b -> r -> r
Put that together with the signature
test :: (A a b) -> a -> b
and unify, ignoring the type error from the first equation, the type is refined to
test :: A r r -> r -> r
Then look at the equation
test AApply a = undefined
and see how that is inaccessible under the refined type, since
AApply :: A (A b c) c
would entail
c ~ A b c
if AApply
were a valid first argument.