"coverage condition"是什么?



mtl 中State变压器的源状态为:

-- ---------------------------------------------------------------------------
-- Instances for other mtl transformers
--
-- All of these instances need UndecidableInstances,
-- because they do not satisfy the coverage condition.

什么是"承保条件"?我只能说它与MTPC和Fundeps有关。

GHC手册的第7.6.3.2节告诉我们覆盖条件是什么:

承保条件。对于类的每个函数依赖关系tvsleft -> tvsrightS(tvsright)中的每个类型变量都必须出现在S(tvsleft)中,其中S是将类声明中的每个类型变量映射到实例声明中的相应类型的替换。

用简单的英语来说,这意味着如果你有一个带有fundeps的类型类,例如:

class Convert a b | a -> b where
  convert :: a -> b

您可以定义以下实例:

instance Convert String String   -- no type variables
instance Convert [a]    [a]      -- type var a present on both sides
instance Convert (a,b)  a        -- a on the right => a on the left

不包括以下实例:

instance Convert String a        -- a only present on the right
instance Convert a      (a,b)    -- b only present on the right

本文由Simon Peyton-Jones定义。定义 7 定义Coverage Condition 。我会引用确切的定义,但唉,我不知道如何在这里重现数学符号。

相关内容

最新更新