for review: move det_univ_to_type

Tyson Dowd trd at cs.mu.OZ.AU
Fri Mar 13 16:25:51 AEDT 1998


Hi,

Mark, care to review this?

===================================================================


Estimated hours taken: 0.5

library/std_util.m:
library/term.m:
	Move det_univ_to_type from term.m to std_util.m, and
	add better error reporting (print the types of the univ
	and the data).

Index: library/std_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/std_util.m,v
retrieving revision 1.115
diff -u -r1.115 std_util.m
--- std_util.m	1998/01/30 02:15:04	1.115
+++ std_util.m	1998/03/13 04:12:12
@@ -66,6 +66,13 @@
 :- mode univ(di) = uo is det.
 :- mode univ(out) = in is semidet.
 
+	% det_univ_to_type(Univ, Object):
+	% 	the same as the forwards mode of univ_to_type, but
+	% 	abort if univ_to_type fails.
+	%
+:- pred det_univ_to_type(univ, T).
+:- mode det_univ_to_type(in, out) is det.
+
 	% univ_type(Univ):
 	%	returns the type_info for the type stored in `Univ'.
 	%
@@ -937,6 +944,18 @@
 univ_to_type(Univ, X) :- type_to_univ(X, Univ).
 
 univ(X) = Univ :- type_to_univ(X, Univ).
+
+det_univ_to_type(Univ, X) :-
+	( type_to_univ(X0, Univ) ->
+		X = X0
+	;
+		UnivTypeName = type_name(univ_type(Univ)),
+		ObjectTypeName = type_name(type_of(X)),
+		string__append_list(["det_univ_to_type: conversion failed\n",
+			"\tUniv Type: ", UnivTypeName,
+			"\n\tObject Type: ", ObjectTypeName], ErrorString),
+		error(ErrorString)
+	).
 
 /****
 
Index: library/term.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/term.m,v
retrieving revision 1.80
diff -u -r1.80 term.m
--- term.m	1998/03/03 17:26:08	1.80
+++ term.m	1998/03/12 04:57:18
@@ -504,16 +504,6 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred det_univ_to_type(univ::in, T::out) is det.
-det_univ_to_type(Univ, Value) :-
-	( univ_to_type(Univ, Value1) ->
-		Value = Value1
-	;
-		error("det_univ_to_type: univ_to_type failed")
-	).
-
-%-----------------------------------------------------------------------------%
-
 /**********
 XXX existential types not yet implemented
 :- some [T] pred has_type(T::unused, type_info::in) is det.

-- 
       Tyson Dowd           # There isn't any reason why Linux can't be
                            # implemented as an enterprise computing solution.
     trd at cs.mu.oz.au        # Find out what you've been missing while you've
http://www.cs.mu.oz.au/~trd # been rebooting Windows NT. -- InfoWorld, 1998.



More information about the developers mailing list