[m-rev.] Re: for review: default modes for higher-order func insts

David Overton dmo at cs.mu.OZ.AU
Thu Oct 11 14:59:02 AEST 2001


On Wed, Oct 10, 2001 at 05:08:40PM +1000, Fergus Henderson wrote:
> On 10-Oct-2001, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > +++ tests/hard_coded/ho_func_default_inst.m
> > @@ -17,27 +17,44 @@
> >  	{ Map = map },
> >  	{ F1 = Map ^ det_elem(1) },
> >  	{ F2 = Map ^ det_elem(2) },
> > -	io__write_string(F1(1)),
> > +	io__write_int(F1(1)),
> >  	io__nl,
> >  	write_func(F2).
> >  
> > -:- type t == (func(int) = string).
> > +:- type t == (func(int) = int).
> ...
> >  :- func map = map(int, t).
> >  
> > -map = (map__init ^ elem(1) := hello) ^ elem(2) := world.
> > +map = (((map__init
> > +		^ elem(1) := foo1)
> > +		^ elem(2) := foo2)
> > +		^ elem(3) := foo3)
> > +		^ elem(4) := foo4.
> ...
> > +:- func foo4(int) = int.
> > +:- mode foo4(in(one)) = out is det.
> 
> Surely it should be an error to insert foo4 into that map?
> 
> E.g. consider the following code:
> 
> 	main -->
> 		{ F4 = map ^ det_elem(4) },
> 		io__write_int(F4(42)).
> 
> This will end up calling foo4(42), so it ought to be a mode error.

Yes, you are right.  The reason no mode error is reported is because of
this code in inst_match.m, which does the required check and the ignores
the result:

inst_matches_final_3(ground(UniqA, GroundInstInfoA), bound(UniqB, ListB),
		MaybeType, Info, Info) :-
	\+ ground_inst_info_is_nonstandard_func_mode(GroundInstInfoA,
		Info^module_info),
	unique_matches_final(UniqA, UniqB),
	bound_inst_list_is_ground(ListB, Info^module_info),
	uniq_matches_bound_inst_list(UniqA, ListB, Info^module_info),
	(
		MaybeType = yes(Type),
		% We can only do this check if the type is known.
		bound_inst_list_is_complete_for_type(set__init,
			Info^module_info, ListB, Type)
	;
		true
		% XXX enabling the check for bound_inst_list_is_complete
		% for type makes the mode checker too conservative in
		% the absence of alias tracking, so we currently always
		% succeed, even if this check fails.
	).


I will remove that test from the test case.

-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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