[Haskell-cafe] instance deduction and phantom types

Jason Dagit dagit at codersbase.com
Thu Aug 7 21:28:37 EDT 2008


I recently had a problem where GHC couldn't deduce some type classes from my
constraints.  I would get error messages like:
Could not deduce (Conflict (PatchInfoAnd p),
                       Patchy (PatchInfoAnd p))
       from the context (RepoPatch p)

But, I had some instances like this (minus the function definitions):
class (Patchy p, Effect p, FromPrims p, Conflict p) => RepoPatch p

instance Effect p => Effect (PatchInfoAnd p)

instance Conflict (p x y) => Conflict (PatchInfoAnd (p x y))

instance RepoPatch (p x y) => Patchy (PatchInfoAnd (p x y))

The x and y in the last two are just phantom types on p.  When I noticed
that the phantom types were missing from the instance definition of Effect
(PatchInfoAnd p), I removed them from the last two definitions.  This made
the "Could not deduce..." error message disappear.

Why do the phantom types not belong in the instance definition?  I'd like to
understand the problem more fully, but I'm not sure what the problem is or
how to get started researching it, so if someone could point me in the right
direction I'd be very happy!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080807/7cbcfb92/attachment.htm

More information about the Haskell-Cafe mailing list