为什么这个内射型家庭实际上不是内射型?

Ash*_*ley 5 haskell ghc type-families

我尝试了这个:

{-# LANGUAGE TypeFamilyDependencies #-}
module Injective where

type family F (a :: *) = (fa :: *) | fa -> a

convert :: F a ~ F b => a -> b
convert x = x
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

为什么?当然,单射性的全部要点是可以从中推论a ~ b得出F a ~ F b吗?

Ash*_*ley 7

事实证明这是GHC 中的一个已知问题。显然这是因为它尚未被证明是正确的。

  • 事实上,假设类型族是完整的,众所周知是不合理的。(请参阅 Eisenberg+Morris 论文。)如果您提供“type instance Fa = a”,则代码可以编译,但如果您提供的实例不那么通用,则不会编译。 (2认同)