[m-users.] Mode selection
Julien Fischer
jfischer at opturion.com
Thu Oct 16 12:33:43 AEDT 2014
On Thu, 16 Oct 2014, Paul Bone wrote:
>
> This question came up on IRC today. Consider append/3:
>
> :- pred append(list(T), list(T), list(T)).
> :- mode append(in, in, out) is det.
> :- mode append(out, out, in) is multi.
>
> And a call to append with each of it's arguments fully instantiated.
>
> % I've written these out so that I can name them and refer to them
> % below.
> A = [1, 2],
> B = [3],
> C = [1, 2, 3],
> append(A, B, C).
>
> This is a case where "append(in, in, in) is semidet" is an implied mode.
> While it makes no (declarative semantics) difference, which mode of append
> will be used here? Does the compiler select the first mode that fits or the
> "best" mode?
>
> A follow up question. What if the implied mode is written down in the
> declaration.
See the comment above the predicate choose_best_match/8 in
compiler/modecheck_call.m. It describes the selection algorithm used.
Or indeed just see the mailing list archives, as this question has
been asked (and answered!) before.
Cheers,
Julien.
More information about the users
mailing list