Haskell functional dependency conflict
-
02-11-2019 - |
Question
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
?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow