[m-rev.] for review: functional dependencies

Mark Brown mark at cs.mu.OZ.AU
Thu Jun 8 00:35:58 AEST 2006


On 07-Jun-2006, Julien Fischer <juliensf at cs.mu.OZ.AU> wrote:
> 
> On Wed, 7 Jun 2006, Mark Brown wrote:
> > Use functional dependencies on superclasses (in addition to the class itself)
> > to relax the restrictions on method constraints.

> 
> That's fine, although I think the functional dependencies section of the
> reference manual should mention the relationship between superclass fds
> and subclasses.

Done.  I've also fixed a pre-existing omission.  Relative diff follows.

Cheers,
Mark.

only in patch2:
unchanged:
--- doc/reference_manual.texi	5 Jun 2006 02:26:12 -0000	1.352
+++ doc/reference_manual.texi	7 Jun 2006 14:31:29 -0000
@@ -5382,8 +5382,9 @@
 
 The extra requirements that result from the use of functional dependencies
 allow the bindings of some variables to be determined from the bindings
-of others.  This in turn relaxes some of the requirements on typeclass
-constraints on predicate and function signatures.
+of others.  This in turn relaxes some of the requirements of typeclass
+constraints on predicate and function signatures,
+and on existentially typed data constructors.
 
 Without any functional dependencies, all variables in constraints must
 appear in the signature of the predicate or function being declared.
@@ -5432,6 +5433,24 @@
 that only uses the first parameter, @var{A}, since the second parameter,
 @var{B}, would always be determined from the first.
 
+Note that, since all instances must satisfy the superclass constraints,
+the restrictions on instances obviously transfer from superclass to
+subclass.  Again, this allows the requirements of typeclass constraints
+to be relaxed.  Thus, the functional dependencies on the ancestors
+of constraints also induce functional dependencies on the variables,
+and the closure that we calculate takes these into account.
+
+For example, in this code
+
+ at example
+	:- typeclass quux(P, Q, R) <= baz(R, P) where @dots{}
+
+	:- pred q(Q, R) <= quux(P, Q, R).
+ at end example
+the signature of @code{q/2} is acceptable since the superclass constraint
+on @code{quux/2} induces the dependency @samp{R -> P} on the type variables,
+hence @var{P} is in the closure of @{@var{Q}, @var{R}@}.
+
 The presence of functional dependencies also allows ``improvement'' to
 occur during type inference.  This can occur in two ways.
 First, if two constraints of a given class match on all of the domain
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list