[m-users.] Why can't `det` be used where `multi` is expected.
Julien Fischer
jfischer at opturion.com
Mon Aug 5 15:46:09 AEST 2019
On Mon, 5 Aug 2019, Philip White wrote:
> The type [get_opt.option_ops] provides a choice between [option_ops] and
> [option_ops_multi], both of which contain short, long, and default
> option predicates. The difference is that [option_ops] expects the
> predicate for default option values to be [nondet], but
> [option_ops_multi] expects it to be [multi].
>
> Below, my predicate, [option_default/2], is declared as [multi], and
> this whole program compiles. However, [option_default/2] is clearly
> deterministic, and indeed the compiler warns that I could be more
> specific. However, if I take the suggestion, then I get nasty
> instantiatedness errors. It would seem to me that passing a
> deterministic predicate into a place which expects a [multi] predicate
> is always valid. What am I not understanding?
`pred(out, out) is multi' and `pred(out, out) is det' are different
insts; you cannot substitute the latter for the former.
The reason is that determinism affects the calling convention used by
the generated code for a predicate.
The warning is correct, the determinism could be tighter, but in this
case for the insts to match you need to keep the determinism as multi.
Add the following:
:- pragma no_determinism_warning(option_default/2).
to shut the warning up.
(This above is only going to be an issue where you have a single
option obviously.)
Julien.
More information about the users
mailing list