的来源Statemtl 中的变压器 http://hackage.haskell.org/packages/archive/mtl/2.1.2/doc/html/src/Control-Monad-State-Class.html states:
-- ---------------------------------------------------------------------------
-- Instances for other mtl transformers
--
-- All of these instances need UndecidableInstances,
-- because they do not satisfy the coverage condition.
什么是“覆盖条件”?我只能说这与 MTPC 和 Fundeps 有关。
第 7.6.3.2 节GHC 手册 http://www.haskell.org/ghc/docs/7.0.1/html/users_guide/type-class-extensions.html告诉我们覆盖条件是什么:
覆盖条件。对于每个函数依赖项,tvsleft -> tvsright
,类中的每个类型变量S(tvsright)
必须出现在S(tvsleft)
, where 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
but not以下情况:
instance Convert String a -- a only present on the right
instance Convert a (a,b) -- b only present on the right
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)