我试过这个:
{-# LANGUAGE TypeFamilyDependencies #-}
module Injective where
type family F (a :: *) = (fa :: *) | fa -> a
convert :: F a ~ F b => a -> b
convert x = x
GHC 8.6.4给了我这个错误
• Could not deduce: a ~ b
from the context: F a ~ F b
bound by the type signature for:
convert :: forall a b. (F a ~ F b) => a -> b
at Injective.hs:6:1-30
为什么?当然,注入的全部意义在于,人们可以从a ~ b
中推断出F a ~ F b
?
原来这是a known issue in GHC。显然这是因为它没有被证明是合理的。