[m-rev.] diff: implement deconstruct for arrays in mercury

Peter Ross pro at missioncriticalit.com
Tue Dec 3 22:25:09 AEDT 2002


On Tue, Dec 03, 2002 at 04:06:45PM +1100, Fergus Henderson wrote:
> On 02-Dec-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> > +++ rtti_implementation.m	2 Dec 2002 17:21:07 -0000
> > @@ -813,9 +813,20 @@
> >  		Arguments = []
> >  	;
> >  		TypeCtorRep = array,
> > +		det_dynamic_cast(Term, Array),
> > +		std_util__type_ctor_and_args(std_util__type_of(Term), _, Args),
> > +		( Args = [ElemType] ->
> > +			std_util__has_type(Elem, ElemType),
> > +			same_array_elem_type(Array, Elem)
> > +		;
> > +			error("An array which doesn't have type_ctor arg")
> > +		),
> 
> IMHO it would be clearer to write this code with the call to det_dynamic_cast
> after the if-then-else here.  That's the order in which the code will
> actually be invoked; the Mercury compiler will delay the call to
> det_dynamic_cast until after the call to `has_type'.
> 
Hi,


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


Estimated hours taken: 0.1
Branches: main

library/rtti_implementation.m:
	Address fjh's review comments.


Index: rtti_implementation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rtti_implementation.m,v
retrieving revision 1.34
diff -u -r1.34 rtti_implementation.m
--- rtti_implementation.m	2 Dec 2002 17:23:05 -0000	1.34
+++ rtti_implementation.m	3 Dec 2002 10:48:50 -0000
@@ -813,14 +813,18 @@
 		Arguments = []
 	;
 		TypeCtorRep = array,
-		det_dynamic_cast(Term, Array),
+
+		% Constrain the T in array(T) to the correct element type.
 		std_util__type_ctor_and_args(std_util__type_of(Term), _, Args),
 		( Args = [ElemType] ->
 			std_util__has_type(Elem, ElemType),
 			same_array_elem_type(Array, Elem)
 		;
-			error("An array which doesn't have type_ctor arg")
+			error("An array which doesn't have a type_ctor arg")
 		),
+
+		det_dynamic_cast(Term, Array),
+
 		Functor = "<<array>>", 
 		Arity = array__size(Array),
 		Arguments = array__foldr(

--------------------------------------------------------------------------
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