[Haskell-cafe] Inferring types from functional dependencies

Jeff.Harper at handheld.com Jeff.Harper at handheld.com
Fri Jun 16 15:44:17 EDT 2006

Thank you.  I followed your suggestion and implemented my default Divide 
as you've shown below.

oleg at pobox.com wrote:
> If we assume that we need Reciprocate only if we are going to use the 
> 'default' method, the solution becomes obvious. It does involve
> overlapping and undecidable instances, sorry. These extensions are
> really useful in practice. Here's the solution:
> > class Divide a b c | a b -> c where
> >     (/) :: a -> b -> c
> Here's the most general instance. It applies when nothing more
> specific does.  It is in this case that we insist on being able to
> take the reciprocal:
> > instance (Reciprocate b recip, Multiply a recip c) =>
> >     Divide a b c where
> >     (/) x y = x * (recip y)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20060616/9e4d147e/attachment-0001.htm

More information about the Haskell-Cafe mailing list