[Haskell-cafe] Functional Dependencies conflicts

Casey McCann syntaxglitch at gmail.com
Sat Apr 17 16:59:19 EDT 2010


On Sat, Apr 17, 2010 at 4:01 PM, Limestraël <limestrael at gmail.com> wrote:
> I would have undestood the error if GameObject was also an instance of
> Binary (then the two instances would match), but it's not the case...

As Daniel Fischer has mentioned, presumably a Binary instance could
later be written for GameObject; even if you have no intention of
doing so, GHC considers the possibility. In other words, it's
sufficient that such an instance could exist, not that it actually
does.

In general: Instance selection and context checking are separate and
occur in that order, thus contexts generally can't influence instance
selection (except by using OverlappingInstances and strategically
confusing instance heads, ensuring that GHC can't make any sense of
your code until considering the contexts).

Unfortunately, anything involving extremely generic instances with
some constraint tend to be very difficult to construct, because of how
this works. This tends to include things like default instances for
types not covered by specific ones, making all instances of X also
instances of Y, fundep "type predicates" based on class membership,
and so on. Type hackery can often get you most of what you want, but
it gets awkward fast.

- C.


More information about the Haskell-Cafe mailing list