Haskell functional dependency conflict
-
02-11-2019 - |
문제
Why does this result in a conflict?
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
Note that the code will compile if I remove the functional dependecy.
I was under the impression that functional dependencies should only disallow stuff like the following, when in fact, it compiles!
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
Same b
parameter, yet different a
parameters. Shouldn't b -> a
disallow this, as this means a
is uniquely determined by b
?
올바른 솔루션이 없습니다
제휴하지 않습니다 StackOverflow