Dan*_*ton 8 haskell functional-dependencies
-- ---------------------------------------------------------------------------
-- Instances for other mtl transformers
--
-- All of these instances need UndecidableInstances,
-- because they do not satisfy the coverage condition.
Run Code Online (Sandbox Code Playgroud)
什么是"覆盖条件"?我只能说它与MTPC和fundeps有关.
opq*_*nut 15
GHC手册第7.6.3.2节告诉我们覆盖条件是什么:
覆盖条件.对于类的每个函数依赖
tvsleft -> tvsright项,每个类型变量S(tvsright)必须出现在S(tvsleft),其中S,将类声明中的每个类型变量映射到实例声明中的相应类型.
简单来说,这意味着如果你有一个带有fundeps的类型类,例如:
class Convert a b | a -> b where
convert :: a -> b
Run Code Online (Sandbox Code Playgroud)
您可以定义以下实例:
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
Run Code Online (Sandbox Code Playgroud)
但不是以下情况:
instance Convert String a -- a only present on the right
instance Convert a (a,b) -- b only present on the right
Run Code Online (Sandbox Code Playgroud)