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 inS(tvsright)
must appear inS(tvsleft)
, whereS
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/