[m-dev.] Array modes

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Oct 24 19:52:26 AEDT 2014



On Fri, 24 Oct 2014 16:06:50 +1100, Peter Wang <novalazy at gmail.com> wrote:
> The [intended] modes in the existing array.m don't make sense to me,
> e.g.
> 
>     :- pred lookup(array(T), int, T).
>     %:- mode lookup(array_ui, in, out) is det.
> 
> At the end of the call, the array is not unique in its elements as the
> third argument shares a reference with one of its elements.
> 
>     :- pred set(int, T, array(T), array(T)).
>     :- mode set(in, in, array_di, array_uo) is det.
> 
> Placing the non-unique value into the array makes it not unique in its
> elements.

In the insts array_{ui,di,uo}, the uniqueness was always only intended
to refer to the memory of the array itself, not to the uniqueness of
the elements. The main concern of the array operations is: do they
have to copy an array if you want a modified version of it, or can they
do the update in place?

Preserving information about the uniqueness of the array elements
was not a design concern at the time, simply because even if you could
preserve that information, the compiler could not exploit it.

Given this view, I don't see anything wrong with the current modes
in array.m. It does seem that the documentation could explain the above
better.

Zoltan.




More information about the developers mailing list