diff: typeclass user documentation

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jan 23 15:48:44 AEDT 1998


On 23-Jan-1998, David Glen JEFFERY <dgj at cs.mu.OZ.AU> wrote:
> > In other words:
> > 
> >     An @samp{instance} declaration gives a type for each parameter of the
> >     typeclass. Each of these types must be either a simple type, ie. a
> >     type with no arguments, or a polymorphic type whose arguments are
> >     all distinct type variables.  For example, @code{int}, @code{list(T)} and
> >     @code{map(K,V)} are allowed, but @code{T}, @code{list(int)} and
> >     @code{map(T,T)} are not.
> 
> My only gripe about this is that is conflicts with the definition of "simple
> type" I was using from the "exploration of the design space" paper.

OK, in that case perhaps we should delete the "a simple type, ie.".

> Also, do you really think that type classes should come after the module 
> system?  The way I see it, type classes are part of the type system, but need 
> to come after modes and determinism are explained.

I'm undecided.  The arguments in favour of listing the module system before 
type classes are:
	
	- you need to know how to use the module system to write
	  "hello world", whereas you don't need to know anything about
	  type classes

	- the module system lets you build modules with a single interface
	  and a single implementation, whereas type classes are for the
	  (more complicated) situations where you want multiple
	  implementations of the same interface.

> + at node Type classes
> + at chapter Type classes
> +
> +Mercury supports constrained polymorphism in the form of type classes.
> +Type classes allow the programmer to write predicates and functions which 
> +operate on variables of any type (or sequence of types) for which a certain set
> +of operations is defined.

Hmm.  Maybe "set of types" is better here after all.

> +        func inverse(T::in) = (T::out) is semidet       % multiplicative 
> +							% inverse

Inconsistent use of tabs.

Please check that you don't introduce any (new) overly long lines
(i.e. overful mboxes, in TeX-speak) when making the printed manual.

> + at example
> +:- typeclass  euclidean(T) <= ring(T) where [

s/  / /
  ^^ ^

> +However, when it comes to writing the instance declaration for a type such as
> + at code{list(T)}, we want to be able print out the list elements using the
> + at code{print/3} for the particular type of the list elements. This can be

s/print/portray/

-- 
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.



More information about the developers mailing list