[m-dev.] Array modes

Mark Brown mark at mercurylang.org
Sat Oct 25 15:35:25 AEDT 2014


On Fri, Oct 24, 2014 at 7:52 PM, Zoltan Somogyi
<zoltan.somogyi at runbox.com> wrote:
>
>
> 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.

The comments here are particularly misleading, I think:

    % :- inst uniq_array == uniq_array(unique).
    :- inst uniq_array == uniq_array(ground).   % XXX work-around

The latter is what is intended; it is not a workaround.

Cheers,
Mark.



More information about the developers mailing list