[mercury-users] Predicate call uses the "wrong" mode
Nicholas Nethercote
njn at csse.unimelb.edu.au
Mon Aug 6 20:27:18 AEST 2007
On Mon, 6 Aug 2007, Peter Schachte wrote:
> 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.
We have a similar thing in Zinc with overloading, and solve it by requiring
that there be a version that is the glb of all the different signatures.
Eg. if you have
f(int, float) -> float
f(float, int) -> float
you also have to provide
f(int, int) -> float
which is the glb of the other two. (Zinc has automatic int-to-float
coercions, which is why this is required.)
The question for Mercury then becomes: what is the glb mean over modes and
determinisms? For 'foo' above, I would guess:
:- mode foo(in, in) is det.
But maybe there are other complications I'm unaware of.
Nick
--------------------------------------------------------------------------
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