[m-dev.] for review: RTTI for existential types

David Glen JEFFERY dgj at cs.mu.OZ.AU
Wed Nov 24 18:17:50 AEDT 1999


On 24-Nov-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> 
> I have a few comments below.  Byt my main criticism is that you
> should add some test cases. 

Oops. Left that out of the diff. The test case below just does lots of
io__writes on various combinations of types.

I will also add a test case for deep_copy (although I expect I will have to
change MR_make_type_info first).

Index: Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/Mmakefile,v
retrieving revision 1.72
diff -u -t -r1.72 Mmakefile
--- Mmakefile	1999/11/12 03:47:05	1.72
+++ Mmakefile	1999/11/24 07:09:58
@@ -34,6 +34,7 @@
         elim_special_pred \
         existential_bound_tvar \
         existential_reordering \
+        existential_rtti \
         existential_type_switch \
         existential_type_switch_opt \
         existential_types_test \
existential_rtti.m:
=================================
% Test cases for rtti for existential types.

:- module existential_rtti.

:- interface.

:- typeclass c(T) where [].

:- instance c(int) where [].

:- type f(X) ---> some [T] f(int, T, list(X), int).

:- type myf  ---> some [T] myf(T) => c(T).

:- type f 
	---> 	some [T] f(int, T, int)
	; 	some [X] g(float, X, float)
	.

:- type g 
	---> 	some [T] g(T).

:- type g2 ---> g2(int).

:- type foo ---> foo(string, string).
:- type goo ---> goo ; hoo.

:- type u(X) ---> u(X).

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- import_module list, std_util.

main -->
	io__write('new myf'(1)),
	io__nl,

		% different types inside
	io__write('new f'(1, "hello", 42)),
	io__nl,
	io__write('new f'(2, "world", 42)),
	io__nl,

		% an enum
	io__write('new f'(3, goo, 42)),
	io__nl,

		% existential inside an existential
	io__write('new f'(4, 'new g'("hello"), 42)),
	io__nl,

		% A no-tag inside
	io__write('new f'(5, g2(12), 42)),

	io__write('new f'(5, foo("hello", "world"), 42)),
	io__nl,

	io__write('new g'(7.0, 'new g'("hello"), 42.0)),
	io__nl,

		% universally quantified argument.
	{ Term = 'new f'(6, u("hello"), 42) },
	{ deconstruct(Term, _Functor, _Arity, Args) },
	io__write_list(Args, ", ", io__write),
	io__nl,
	io__write(Term),

	io__nl.


existential_rtti.exp:
=================================
myf(1)
f(1, "hello", 42)
f(2, "world", 42)
f(3, goo, 42)
f(4, g("hello"), 42)
f(5, g2(12), 42)f(5, foo("hello", "world"), 42)
g(7.00000000000000, g("hello"), 42.0000000000000)
univ(6 : int), univ(u("hello") : existential_rtti:u(string)), univ(42 : int)
f(6, u("hello"), 42)


dgj
-- 
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student,                    | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.|     With sufficient formality
The University of Melbourne     |     The sheerist banality
Australia                       | Will be hailed by the critics: "Miraculous!"
                                |     -- Anon.
--------------------------------------------------------------------------
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