[m-dev.] for review: head_type_params for class methods

David Glen JEFFERY dgj at cs.mu.OZ.AU
Fri Jul 9 14:31:56 AEST 1999


This one is for Fergus:


Estimated hours taken: 2

compiler/typecheck.m:
	Set the head_type_params field of class methods properly. (ie. add
	the existentially quantified tvars as well).

compiler/hard_coded/typeclasses/typeclass_exist_method.m:
	A test case for this.
compiler/hard_coded/typeclasses/Mmakefile:
	Turn this test case on.

cvs diff: Diffing compiler
Index: compiler/typecheck.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/typecheck.m,v
retrieving revision 1.260
diff -u -t -r1.260 typecheck.m
--- typecheck.m	1999/07/08 08:15:18	1.260
+++ typecheck.m	1999/07/08 08:41:20
@@ -352,7 +352,15 @@
                         clauses_info_set_vartypes(ClausesInfo0, VarTypes,
                                 ClausesInfo),
                         pred_info_set_clauses_info(PredInfo0, ClausesInfo,
-                                PredInfo),
+                                PredInfo1),
+                                % We also need to set the head_type_params
+                                % field to indicate that all the existentially
+                                % quantified tvars in the head of this
+                                % pred are indeed bound by this predicate.
+                        term__vars_list(ArgTypes0,
+                                HeadVarsIncludingExistentials),
+                        pred_info_set_head_type_params(PredInfo1,
+                                HeadVarsIncludingExistentials, PredInfo),
                         Error = no,
                         Changed = no
                 ;
cvs diff: Diffing compiler/notes

cvs diff: Diffing .
cvs diff: Diffing sub-modules
cvs diff: Diffing typeclasses
Index: typeclasses/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/hard_coded/typeclasses/Mmakefile,v
retrieving revision 1.17
diff -u -t -r1.17 Mmakefile
--- Mmakefile	1999/06/30 17:13:35	1.17
+++ Mmakefile	1999/07/08 08:25:16
@@ -28,6 +28,7 @@
         operator_classname \
         superclass_call \
         test_default_func_mode \
+        typeclass_exist_method \
         typeclass_test_5 \
         typeclass_test_6 \
         use_abstract_instance
cvs diff: typeclasses/typeclass_exist_method.exp is a new entry, no comparison available
cvs diff: typeclasses/typeclass_exist_method.m is a new entry, no comparison available

typeclass_exist_method.exp:
=======================================================================
42.0000000000000



typeclass_exist_method.m:
=======================================================================
:- module typeclass_exist_method.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module require.

:- typeclass toto(T) where
  [
  ].

:- instance toto(float) where [].
:- instance toto(character) where [].

:- some [V] (pred gen_toto_float(V) => toto(V)).
:- mode gen_toto_float(out) is det.
gen_toto_float(42.0).

:- some [V] (pred gen_toto_char(V) => toto(V)).
:- mode gen_toto_char(out) is det.
gen_toto_char('?').

:- typeclass toto2(T) where
  [
      some[V] (pred gen_toto(T::in, V::out) is det => toto(V))
  ].

:- instance toto2(int) where [
	pred(gen_toto/2) is int_gen_toto
].

:- some [V] (pred int_gen_toto(int, V) => toto(V)).
:- mode int_gen_toto(in, out) is det.
int_gen_toto(X, Y) :-
	( compare(=, X, X) ->
		gen_toto_float(Y)
	;
		error("oops")
	).

main -->
	{ gen_toto(42, Y) },
	write(Y), nl.

:- end_module typeclass_exist_method.


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