为什么这会导致冲突?
class Foo a b | b -> a where
foo :: a -> b -> Bool
instance Eq a => Foo a a where
foo = (==)
instance Eq a => Foo a (a -> a) where
foo x f = f x == x
请注意,如果我删除功能依赖,代码将编译。
我的印象是,函数依赖应该只禁止像下面这样的东西,而事实上,它可以编译!
class Foo a b | b -> a where
foo :: a -> b -> Bool
instance Eq a => Foo a a where
foo = (==)
instance Eq a => Foo Bool a where
foo _ x = x == x
相同b
的参数,但不同的a
参数。不应该b -> a
禁止这样做,因为这意味着a
由b
?