[m-dev.] for review: clarify type classes documentation (was: file streams)
Fergus Henderson
fjh at cs.mu.OZ.AU
Wed Feb 9 18:08:34 AEDT 2000
On 28-Dec-1999, Ralph Becket <rbeck at microsoft.com> wrote:
>
> > From: Fergus Henderson [mailto:fjh at cs.mu.OZ.AU]
> > > Isn't `instance stream__duplex' implied by
> > > `instance stream__{in,out}put'? Or is the
> > > declaration necessary?
> >
> > No, the declaration is necessary. Even if a type class has no
> > methods of its own, you need to an explicit instance declaration
> > for each type that is an instance of that typeclass.
> > After all, in general there might be semantics (e.g. additional
> > axioms) associated with membership in a type class. Possessing
> > definitions for all the methods doesn't necessarily guarantee
> > that a type's semantics are correct for membership in a given
> > type class.
>
> I thought that might be the case; I was taking the notation
> (implication) too literally. Is it worth making a note in the
> reference manual about the distinction?
How about the following?
----------
Estimated hours taken: 0.25
doc/reference_manual.texi:
Some minor clarifications to the documentation of type classes.
Workspace: /d-drive/home/hg/fjh/mercury
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.170
diff -u -d -r1.170 reference_manual.texi
--- doc/reference_manual.texi 2000/02/08 12:18:48 1.170
+++ doc/reference_manual.texi 2000/02/09 07:06:27
@@ -3339,6 +3339,14 @@
@end example
The parameters must be distinct variables.
+Each @code{typeclass} declaration must have at least one parameter.
+
+It is OK for a @code{typeclass} declaration to declare no methods,
+e.g.
+
+ at example
+:- typeclass foo(T) where [].
+ at end example
There must not be more than one type class declaration with the
same name and arity in the same module.
@@ -3395,6 +3403,10 @@
predicate or function specified for that method in the
instance declaration that matches the types of the arguments
to the call.
+
+Note that even if a type class has no methods, an explicit instance
+declaration is required for a type to be considered an instance
+of that type class.
Here's an example of some code using an instance declaration:
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list