[Haskell-cafe] Functional Dependencies conflicts

Casey McCann syntaxglitch at gmail.com
Sun Apr 18 10:08:05 EDT 2010

On Sun, Apr 18, 2010 at 5:01 AM, Limestraël <limestrael at gmail.com> wrote:
> There must be some kind of a private joke I don't get...
> BTW, all you've said is pretty scaring...

And somewhat exaggerated, of course. Reasonable uses exist for all
three extensions, but they're firmly in the category of "avoid unless
you know what you're doing". Well, at least two of them are, I'm not
sure when IncoherentInstances is a good idea (if ever). It's worth
experimenting with them in some toy code for a while before trying to
use them "for real".

In any case, if you do use those extensions, they can usually be
isolated to some extent. A library can use them internally without
requiring client code to enable them, and in an application use can be
restricted to just a few modules, enabling the extensions on a
per-module basis.

My rule of thumb is the "sausage principle"--outside code should be
able to act as if GHC somewhere picked up a more expressive means of
specifying instance heads and/or a smarter termination checker and
carry on blissfully ignorant of by what providence the instances were
obtained. That is, if one eats sausage, it is best to not dwell on how
it is made, so to speak.

> It's strange I can't declare a generic instance for Binary types... I
> thought I was trying to do something quite common in Haskell.
> Apparently I'm still a young padawan with many things to learn.
> Anyway, it's not the first time I get worked up with multi-param typeclasses
> and functionnal dependencies....

What you're trying to do is perfectly reasonable, unfortunately it
doesn't mesh well with how type classes/instances work. A lot of the
reason why the distressing extensions under discussion exist at all is
working around those limitations.

Type families are a start on cleaning up one aspect of the type class
system--namely, the awkwardness of functional dependencies.
Unfortunately, type families don't really help on the "how to write
generic but not completely general instances" right now, and in fact
are incompatible with overlapping instances, making some things
impossible! I think there have been some discussions of proposals
toward fixing this as well, but I'm not sure what the status of those

- C.

More information about the Haskell-Cafe mailing list