[Haskell-cafe] Fundeps and overlapping instances

Etienne Laurin etienne at atnnn.com
Wed May 30 22:31:14 CEST 2012


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



More information about the Haskell-Cafe mailing list