Inferring types from functional dependencies

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Inferring types from functional dependencies

Jeff.Harper

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

[hidden email] 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)


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe