haskell - 什么是 "coverage condition"?

标签 haskell functional-dependencies

The source for the State transformer in mtl状态:

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

什么是“覆盖条件”?我只能说它与 MTPC 和基金组织有关。

最佳答案

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

The Coverage Condition. For each functional dependency, tvsleft -> tvsright, of the class, every type variable in S(tvsright) must appear in S(tvsleft), where S is the substitution mapping each type variable in the class declaration to the corresponding type in the instance declaration.



用简单的英语来说,这意味着如果你有一个带有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

关于haskell - 什么是 "coverage condition"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11959764/

相关文章:

haskell - 将 IO 输出收集到列表中

mysql - 难以掌握 MySQL 的函数依赖概念

database - 计算给定函数依赖性的候选键

Haskell 函数检查数字是否为奇数,而不使用 odd 函数

haskell - 如何根据 Haskell 中的分数列表创建排名?

haskell - 如何在函数式语言中形式化数字塔?

json - 是否可以使用 Text.JSON 在 haskell 中创建嵌套的 JSON 对象?

database - x--->y 是一个微不足道的函数依赖吗?

join - 函数依赖的无损连接和分解