[m-dev.] for review: abstract instance declarations

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Feb 20 07:28:54 AEDT 1999


On 19-Feb-1999, David Glen JEFFERY <dgj at hydra.cs.mu.oz.au> wrote:
> > +Each @samp{instance} declaration
> > +must specify a binding for every method declared in the corresponding
> > + at samp{class} declaration. 
> 
> Is "binding" the right word? The word I normally use is "implementation", but
> I'm not sure that it's quite correct.

You're right that using the word "binding" might well be confusing here.
I've changed it to use "... must define an implementation for ..."

> This sentence should probably also state
> that there must be *exactly* one implementation of each method. Also, the
> declaration is "typeclass", not "class". Maybe:
> 
> 	Each @samp{instance} declaration
> 	must specify exactly one implementation for every method declared in the
> 	corresponding @samp{typeclass} declaration. 

I found it clearer to state that as a separate sentence.

--------------------

Estimated hours taken: 0.25

doc/reference_manual.texi:
	Reword a few things, as suggested by dgj's review of my recent change.
	Also mention that the typeclass constraints on an abstract instance
	declaration must exactly match those on the corresponding definition.

Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.122
diff -u -r1.122 reference_manual.texi
--- reference_manual.texi	1999/02/18 07:59:05	1.122
+++ reference_manual.texi	1999/02/19 20:20:54
@@ -2887,7 +2887,8 @@
 applied to any type (or set of types).
 
 Each entry in the @samp{where [@dots{}]} part of an @code{instance}
-declaration specifies a binding for one of the methods of the class.
+declaration defines the implementation of one of the class methods
+for this instance.
 The @var{predname} or @var{funcname} must name a function or
 predicate of the specified arity whose type, modes, determinism, and
 purity are at least as permissive as the declared type, modes,
@@ -2895,9 +2896,10 @@
 @var{methodname} and @var{arity}, after the types of the arguments
 in the instance declaration have substituted in place of the
 parameters in the typeclass declaration.
-Each @samp{instance} declaration
-must specify a binding for every method declared in the corresponding
- at samp{class} declaration. 
+Each @samp{instance} declaration must define an implementation for
+every method declared in the corresponding @samp{typeclass} declaration.
+It is an error to define more than one implemention for the same
+method within a single @samp{instance} declaration.
 
 Any call to a method must have arguments types (and in the case of functions,
 return type) which are constrained to be a member of that method's
@@ -3148,6 +3150,12 @@
         io__write_char(' '),
         portray_list(Xs).
 @end example
+
+For abstract instance declarations, the type class constraints on an
+abstract instance declaration must exactly match the type class
+constraints on the corresponding non-abstract instance declaration that
+defines that instance.
+ at c XXX The current implementation does not enforce that rule.
 
 @node Semantics
 @chapter Semantics
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger fjh at 128.250.37.3        |     -- leaked Microsoft memo.



More information about the developers mailing list