[m-dev.] making cfloat__init/1 implicit
Andrew Bromage
bromage at cs.mu.oz.au
Tue Sep 16 07:11:20 AEST 1997
G'day.
Fergus Henderson wrote:
> Currently you cannot pass a variable with inst `free' to a
> procedure that expects an argument of inst `any'; instead
> you must explicitly initialize it with a call to cfloat__init/1
> or the like.
>
> The patch below would fix this. However, it turns out to
> cause more problems than it solves. The reason is that
> mode analsis ends up picking the wrong modes -- it prefers
> the semidet ones above the det ones. This causes determinism
> errors...
>
> We should fix mode analysis to use a more sane algorithm for
> picking which mode to call. Then this change can be committed.
> For now I will leave it uncommitted.
Could I suggest that a reasonable first-cut is to search modes in the
order that they are declared independent of their determinisms? We
may have to examine some library predicates to see if their orderings
are "reasonable".
BTW, here's another example which is rejected by determinism analysis
for the same reason:
<<
:- module permutation.
:- interface.
:- import_module list.
:- pred permutation(list(T) :: in, list(T) :: out) is multi.
:- implementation.
permutation([], []).
permutation(Xs, [Y | YsPerm]) :-
Xs = [_ | _],
permutation_2(Y, Xs, Ys), % The nondet mode is incorrectly picked here.
permutation(Ys, YsPerm).
:- pred permutation_2(T, list(T), list(T)).
:- mode permutation_2(out, in(non_empty_list), out) is multi.
:- mode permutation_2(out, in, out) is nondet.
permutation_2(X, [X | Xs], Xs).
permutation_2(X, [Y | Ys], [Y | Zs]) :-
permutation_2(X, Ys, Zs).
>>
Cheers,
Andrew Bromage
More information about the developers
mailing list