[mercury-users] Predicate call uses the "wrong" mode

Peter Schachte schachte at csse.unimelb.edu.au
Mon Aug 6 12:43:43 AEST 2007

Julien Fischer wrote:
> On Sat, 4 Aug 2007, Nikolas Everett wrote:
>> Bug or not, its unexpected.  I expected the compiler to go with the mode
>> that most closely matches the state of the variables.

The problem is that may not be uniquely defined.  If you have

	:- mode foo(out,out) is multi.
	:- mode foo(in, out) is det.
	:- mode foo(out, in) is det.

and call it in mode (in,in), which mode "most closely matches" the state of the
variables?  The only thing you can be sure of is that it's not the first one.
If you instead have

	:- mode foo(out,out) is multi.
	:- mode foo(in, out) is nondet.
	:- mode foo(out, in) is semidet.

would you expect Mercury to prefer the semidet mode over the nondet one, and
choose the third?  That'd be nice.

>> Is there a situation where you'd want to use the implied predicate
>> instead
>> of the explicit one?
> Probably not, although the inverse is sometimes the case.

Is there a situation where you'd prefer a nondet mode over a semidet one or a
multi mode over a det one?  I can't think of one.  And the tricky case:  would
you ever prefer a det mode of over a semidet one, or multi over nondet?  I
suspect not, on the theory that you'd prefer to fail earlier rather than later.

How hard would it be to get the compiler to more intelligently choose the mode
of a call, preferring first according to determinism, second according to most
specific mode, and only third according to the order the modes are listed?

Peter Schachte              [A computer is] like an Old Testament god, with
schachte at cs.mu.OZ.AU        a lot of rules and no mercy.
www.cs.mu.oz.au/~schachte/      -- Joseph Campbell
Phone: +61 3 8344 1338
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list