[m-rev.] Documentation and test case for abstract typeclasses.
Ralph Becket
rafe at cs.mu.OZ.AU
Wed Oct 30 15:41:00 AEDT 2002
Estimated hours taken: 0.5
Branches: main
doc/reference_manual.texi:
Added documentation for abstract typeclass declarations.
Index: reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.259
diff -u -r1.259 reference_manual.texi
--- reference_manual.texi 1 Oct 2002 08:13:26 -0000 1.259
+++ reference_manual.texi 30 Oct 2002 04:36:29 -0000
@@ -4156,6 +4156,7 @@
@menu
* Typeclass declarations::
* Instance declarations::
+* Abstract typeclass declarations::
* Abstract instance declarations::
* Type class constraints on predicates and functions::
* Type class constraints on type class declarations::
@@ -4418,6 +4419,22 @@
Further instances of the type class could be made, e.g.@: a type that represents
the point using polar coordinates.
+
+ at node Abstract typeclass declarations
+ at section Abstract typeclass declarations
+
+Abstract typeclass declarations are typeclass declarations whose
+definitions are hidden. An abstract typeclass declaration has the
+same form as a typeclass declaration, but without the
+ at samp{where[@dots{}]} part. An abstract typeclass declaration
+defines a name for a set of (sequences of) types, but does not define
+what methods must be implemented for instances of the type class.
+
+Like abstract type declarations, abstract typeclass declarations are
+only useful in the interface section of a module. Each abstract
+typeclass declaration must be accompanied by a corresponding
+non-abstract typeclass declaration that defines the methods for
+that type class.
@node Abstract instance declarations
@section Abstract instance declarations
Estimated hours taken: 0.1
Branches: main
tests/Mmakefile:
Added typeclasses subdirectory to list of test directories.
Index: Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/Mmakefile,v
retrieving revision 1.6
diff -u -r1.6 Mmakefile
--- Mmakefile 17 Aug 2002 13:51:54 -0000 1.6
+++ Mmakefile 30 Oct 2002 03:59:31 -0000
@@ -1,6 +1,17 @@
THIS_DIR=tests
PROGS=
TESTS=
-SUBDIRS = benchmarks debugger general hard_coded invalid misc_tests tabling term valid warnings
+SUBDIRS = \
+ benchmarks \
+ debugger \
+ general \
+ hard_coded \
+ invalid \
+ misc_tests \
+ tabling \
+ term \
+ typeclasses \
+ valid \
+ warnings
TESTS_DIR=.
include $(TESTS_DIR)/Mmake.common
Estimated hours taken: 0.5
Branches: main
tests/typeclasses/Mmakefile:
Added.
tests/typeclasses/abstract_typeclasses.m:
tests/typeclasses/abstract_typeclasses.exp:
New test case.
Index: Mmakefile
===================================================================
RCS file: Mmakefile
diff -N Mmakefile
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Mmakefile 30 Oct 2002 03:58:23 -0000
@@ -0,0 +1,31 @@
+#-----------------------------------------------------------------------------#
+
+THIS_DIR = typeclasses
+
+#-----------------------------------------------------------------------------#
+
+# Any program added here should also be added to the `.cvsignore' file.
+
+ORDINARY_PROGS= \
+ abstract_typeclasses
+
+EXCEPTION_PROGS =
+
+ifneq "$(findstring profdeep,$(GRADE))" ""
+ PROGS = $(ORDINARY_PROGS)
+else
+ PROGS = $(ORDINARY_PROGS) $(EXCEPTION_PROGS)
+endif
+
+NOT_WORKING =
+
+SUBDIRS =
+TESTS=$(PROGS)
+TESTS_DIR=..
+include $(TESTS_DIR)/Mmake.common
+
+# Module-specific options should go in Mercury.options so they
+# can be found by `mmc --make'.
+include Mercury.options
+
+%.runtest: %.res ;
Index: abstract_typeclasses.exp
===================================================================
RCS file: abstract_typeclasses.exp
diff -N abstract_typeclasses.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ abstract_typeclasses.exp 30 Oct 2002 04:00:40 -0000
@@ -0,0 +1 @@
+double(2) = 4
Index: abstract_typeclasses.m
===================================================================
RCS file: abstract_typeclasses.m
diff -N abstract_typeclasses.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ abstract_typeclasses.m 30 Oct 2002 03:58:31 -0000
@@ -0,0 +1,44 @@
+%-----------------------------------------------------------------------------%
+% abstract_typeclasses.m
+% Ralph Becket <rafe at cs.mu.oz.au>
+% Wed Oct 30 14:53:53 EST 2002
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%
+%-----------------------------------------------------------------------------%
+
+:- module abstract_typeclasses.
+
+:- interface.
+
+:- import_module io, int.
+
+
+
+:- typeclass tc(T).
+
+:- instance tc(int).
+
+
+
+:- pred main(io::di, io::uo) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module string, list.
+
+
+
+:- typeclass tc(T) where [ func double(T) = T ].
+
+:- instance tc(int) where [ double(X) = X + X ].
+
+%-----------------------------------------------------------------------------%
+
+main(!IO) :-
+ io__format("double(2) = %d\n", [i(double(2))], !IO).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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