什么是“覆盖条件”? [英] What is the "coverage condition"?

查看:176
本文介绍了什么是“覆盖条件”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

State mtl转换器的来源:

   -  ---------------------------------------------- ----------------------------- 
- 其他mtl转换器的实例
-
- 所有这些实例都需要UndecidableInstances,
- 因为它们不符合覆盖条件。

什么是覆盖条件?我只能说,它与MTPC和fundeps有关。 第7.6.3.2节 GHC手册告诉我们什么覆盖面条件是:


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


< blockquote>

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

  class转换ab | a  - > b其中
convert :: a - > b

您可以定义以下实例:

 实例转换字符串字符串 - 无类型变量
实例转换[a] [a] - 类型var双方存在
实例转换(a, b)a - 右侧=> a在左边

不是下列情况:

  instance转换字符串a  - 仅存在于右边
实例转换a(a,b) - b仅存在于正确的


The source for the State transformer in mtl states:

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

What is the "coverage condition"? All I can tell is that it has something to do with MTPCs and fundeps.

解决方案

Section 7.6.3.2 of the GHC manual tells us what the coverage condition is:

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.

In plain English, this means that if you have a type class with fundeps, for example:

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

you can define the following instances:

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

but not the following instances:

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

这篇关于什么是“覆盖条件”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆