
Hello,
the notion of a functional dependency is well established, and it was used
well before it was introduced to Haskell (for example, take a look at
http://en.wikipedia.org/wiki/Functional_dependency). So I'd be weary to
redefine it lightly.
Note that placing a functional dependency constraint is just one way to
allow class methods that don't mention all class variables. If the
instances for the class do not satisfy the functional dependency (as in
your example), you can refactor your class hierarchy, instead. For example:
class D a where k :: a
class D a => C a b where f :: a -> b
instance D Int where k = 2
instance C Int b where f _ = Nothing
I hope this helps,
-Iavor
On Wed, May 30, 2012 at 1:31 PM, Etienne Laurin
Hello,
I disagree with your example.
1. Check that an instance is consistent with itself. For example, this should be rejected:
instance C a b
because it allows C Int Bool and C Int Char which violate the functional dependency.
Functional dependencies are not used to pick types, they are used to pick instances.
class C a b | a → b where k ∷ a f ∷ a → Maybe b
The functional dependency allows you to have a method such as k that doesn't use all the arguments of the class.
I expect to be able to make a instance that works for any b.
instance C Int b where k = 2 f _ = Nothing
Etienne Laurin