[m-dev.] diff: add test case for typeclass instances in different modules

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 2 00:51:57 AEDT 2000


Estimated hours taken: 0.5

tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/module_test.m:
tests/hard_coded/typeclasses/module_test_m1.m:
tests/hard_coded/typeclasses/module_test_m2.m:
tests/hard_coded/typeclasses/module_test.exp:
	Add a test case to test my recent change to record the module
	that each instance declaration came from.
	The IL back-end used to fail this test case.
	(Probably it still does, but hopefully for a different reason ;-)

Workspace: /home/pgrad/fjh/fs/roy/traveller/mercury2
Index: tests/hard_coded/typeclasses/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.39
diff -u -d -r1.39 Mmakefile
--- tests/hard_coded/typeclasses/Mmakefile	2000/10/13 08:24:25	1.39
+++ tests/hard_coded/typeclasses/Mmakefile	2000/11/01 13:44:56
@@ -33,6 +33,7 @@
 	intermod_typeclass_bug \
 	lambda_multi_constraint_same_tvar \
 	mode_decl_order_bug \
+	module_test \
 	multi_constraint_diff_tvar \
 	multi_constraint_same_tvar \
 	multi_moded \
@@ -73,6 +74,9 @@
 MCFLAGS-unqualified_method = --intermodule-optimization
 MCFLAGS-unqualified_method2 = --intermodule-optimization
 MCFLAGS-unqualified_method3 = --intermodule-optimization
+MCFLAGS-module_test_m1 = --infer-all
+MCFLAGS-module_test_m2 = --infer-all
+MCFLAGS-module_test = --infer-all
 
 #-----------------------------------------------------------------------------#
 
Index: tests/hard_coded/typeclasses/module_test.exp
===================================================================
RCS file: module_test.exp
diff -N module_test.exp
--- /dev/null	Tue May 16 14:50:59 2000
+++ module_test.exp	Thu Nov  2 00:45:32 2000
@@ -0,0 +1,4 @@
+t1: 1
+string: hello world
+t2: 2
+float: 123.450000000000
Index: tests/hard_coded/typeclasses/module_test.m
===================================================================
RCS file: module_test.m
diff -N module_test.m
--- /dev/null	Tue May 16 14:50:59 2000
+++ module_test.m	Thu Nov  2 00:48:49 2000
@@ -0,0 +1,21 @@
+% This tests the interaction between type classes, instance declarations,
+% and modules.  In particular this test checks that in module `module_test'
+% we can use an instance declaration defined in a different module
+% `module_test_m2' that defines an instance of a type class which is
+% defined in yet another module `module_test_m1'.
+
+:- module module_test.
+:- interface.
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+:- import_module module_test_m1.
+:- import_module module_test_m2.
+
+main -->
+	run(a_t1),
+	run("hello world"),
+	run(a_t2),
+	run(123.45).
Index: tests/hard_coded/typeclasses/module_test_m1.m
===================================================================
RCS file: module_test_m1.m
diff -N module_test_m1.m
--- /dev/null	Tue May 16 14:50:59 2000
+++ module_test_m1.m	Tue Oct 31 22:41:27 2000
@@ -0,0 +1,24 @@
+:- module module_test_m1.
+:- interface.
+:- import_module io.
+
+:- typeclass runnable(T) where [
+	pred run(T::in, io__state::di, io__state::uo) is det
+].
+
+:- type t1.
+:- instance runnable(t1).
+:- instance runnable(string).
+:- func a_t1 = t1.
+
+:- implementation.
+
+:- type t1 ---> t1(int).
+
+a_t1 = t1(1).
+
+:- instance runnable(t1) where [pred(run/3) is run_t1].
+:- instance runnable(string) where [pred(run/3) is run_string].
+
+run_t1(t1(I)) --> io__write_string("t1: "), io__write_int(I), io__nl.
+run_string(S) --> io__write_string("string: "), io__write_string(S), io__nl.
Index: tests/hard_coded/typeclasses/module_test_m2.m
===================================================================
RCS file: module_test_m2.m
diff -N module_test_m2.m
--- /dev/null	Tue May 16 14:50:59 2000
+++ module_test_m2.m	Tue Oct 31 22:41:06 2000
@@ -0,0 +1,20 @@
+:- module module_test_m2.
+:- interface.
+:- import_module module_test_m1.
+
+:- type t2.
+:- func a_t2 = t2.
+:- instance runnable(t2).
+:- instance runnable(float).
+
+:- implementation.
+:- import_module io.
+
+:- type t2 ---> t2(int).
+
+:- instance runnable(t2) where [pred(run/3) is run_t2].
+:- instance runnable(float) where [pred(run/3) is run_float].
+
+a_t2 = t2(2).
+run_t2(t2(I)) --> io__write_string("t2: "), io__write_int(I), io__nl.
+run_float(S) --> io__write_string("float: "), io__write_float(S), io__nl.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- 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