[m-rev.] diff: test case for abstract typeclasses
Mark Brown
dougl at cs.mu.OZ.AU
Wed Oct 23 00:12:54 AEST 2002
Hi,
This is a test case for abstract typeclass definitions, which we pass, but
note that the feature is still not documented in the reference manual.
Patches for that are still welcome. ;-)
Cheers,
Mark.
Estimated hours taken: 0.25
Branches: main
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/abstract_typeclass.m:
tests/hard_coded/typeclasses/use_abstract_typeclass.exp:
tests/hard_coded/typeclasses/use_abstract_typeclass.m:
A test case for abstract typeclass declarations.
Index: tests/hard_coded/typeclasses/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.49
diff -u -r1.49 Mmakefile
--- tests/hard_coded/typeclasses/Mmakefile 15 Oct 2002 14:22:39 -0000 1.49
+++ tests/hard_coded/typeclasses/Mmakefile 22 Oct 2002 13:37:56 -0000
@@ -62,7 +62,8 @@
type_spec \
unbound_tvar \
unqualified_method \
- use_abstract_instance
+ use_abstract_instance \
+ use_abstract_typeclass
TESTS = $(PROGS)
SUBDIRS=
Index: tests/hard_coded/typeclasses/abstract_typeclass.m
===================================================================
RCS file: tests/hard_coded/typeclasses/abstract_typeclass.m
diff -N tests/hard_coded/typeclasses/abstract_typeclass.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/typeclasses/abstract_typeclass.m 22 Oct 2002 13:58:28 -0000
@@ -0,0 +1,48 @@
+:- module abstract_typeclass.
+:- interface.
+:- import_module io, list, string.
+
+:- typeclass foo(T).
+
+:- instance foo(int).
+:- instance foo(string).
+:- instance foo(list(T)) <= foo(T).
+
+:- pred p(T, io__state, io__state) <= foo(T).
+:- mode p(in, di, uo) is det.
+
+:- some [T] pred q(T) => foo(T).
+:- mode q(out) is det.
+
+:- implementation.
+
+:- typeclass foo(T) where [
+ func bar(T) = string
+].
+
+:- instance foo(int) where [
+ (bar(_) = "an integer")
+].
+
+:- instance foo(string) where [
+ (bar(_) = "a string")
+].
+
+:- instance foo(list(T)) <= foo(T) where [
+ (bar([]) = "an empty list"),
+ (bar([H | _]) = string__append("a list, and its head is ", bar(H)))
+].
+
+p(T) -->
+ io__write(T),
+ io__write_strings([" is ", bar(T), ".\n"]).
+
+:- type quux
+ ---> tchok.
+
+:- instance foo(quux) where [
+ (bar(_) = "a quux")
+].
+
+q(tchok).
+
Index: tests/hard_coded/typeclasses/use_abstract_typeclass.exp
===================================================================
RCS file: tests/hard_coded/typeclasses/use_abstract_typeclass.exp
diff -N tests/hard_coded/typeclasses/use_abstract_typeclass.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/typeclasses/use_abstract_typeclass.exp 22 Oct 2002 14:01:20 -0000
@@ -0,0 +1,5 @@
+43 is an integer.
+"Forty-three" is a string.
+[43] is a list, and its head is an integer.
+[[[], [43]]] is a list, and its head is a list, and its head is an empty list.
+tchok is a quux.
Index: tests/hard_coded/typeclasses/use_abstract_typeclass.m
===================================================================
RCS file: tests/hard_coded/typeclasses/use_abstract_typeclass.m
diff -N tests/hard_coded/typeclasses/use_abstract_typeclass.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/typeclasses/use_abstract_typeclass.m 22 Oct 2002 13:59:32 -0000
@@ -0,0 +1,18 @@
+:- module use_abstract_typeclass.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+:- import_module abstract_typeclass.
+:- import_module list.
+
+main -->
+ p(43),
+ p("Forty-three"),
+ p([43]),
+ p([[[], [43]]]),
+ { q(X) },
+ p(X).
+
--------------------------------------------------------------------------
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