[m-rev.] for review: store-based arrays
Mark Brown
mark at mercurylang.org
Thu Jun 9 02:19:46 AEST 2016
Hi Julien,
On Mon, Jun 6, 2016 at 11:02 AM, Julien Fischer <jfischer at opturion.com> wrote:
>
> What's the rationale for adding this? (I don't have any objections but
> am just curious ...)
I've long thought it would be generally useful but hadn't got around
to it. But the random number generator interfaces I posted made me
think of it, because using these kind of arrays would make it
convenient to use the random/2 typeclass directly for generators such
as the xorshift ones, instead of using the two-level typeclass scheme.
I'll post an alternative take on the RNG typeclasses soon.
>
> ...
>
>> commit 5ccf4a9bfb1ff89ec5af4efeb30d243a190f9d41
>> Author: Mark Brown <mark at mercurylang.org>
>> Date: Fri Jun 3 00:04:19 2016 +1000
>>
>> Add mutable arrays to the store module.
>>
>> library/store.m:
>> Implement mutable arrays. These are essentially arrays from the
>> array module with a store-based interface around them.
>>
>> Performing updates with this interface requires a new form of
>> array.unsafe_set to be (privately) exported from the array module.
>>
>> library/array.m:
>> Define array updates in terms of very_unsafe_set, which takes
>> a single array argument and a pair of store arguments, and
>> updates the array in situ. In the case of unique arrays we use
>> the array itself as the "store". This prevents the calls from
>> being optimized away while still allowing inlining.
>>
>> Back-ends that do not use destructive update to implement arrays
>> (namely, Erlang) must implement unsafe_set rather than
>> very_unsafe_set; in this case the latter calls sorry/1, so
>> attempts to use the new interface on these back-ends will
>> currently abort.
>>
>> Export predicates for use by the new code in store.m.
>>
>> NEWS:
>> Announce the addition to the standard library.
>>
>> diff --git a/NEWS b/NEWS
>> index 5628bb5..dbb6262 100644
>> --- a/NEWS
>> +++ b/NEWS
>> @@ -130,6 +130,9 @@ Changes to the Mercury language:
>>
>> Changes to the Mercury standard library:
>>
>> +* We have added a new array type to the store module, in which arrays are
>> + ground values that are accessed via a unique store type such as io.
>
>
> ... such as the I/O state.
Fixed.
>
> ...
>
> The rest looks fine, but I think you ought to provide more of the operations
> from the array module, is_empty, min, max, various folds etc.
Okay. I'll post that as a separate diff, as there will probably be
some bikeshedding to do regarding what exactly to include (for
example, I'm happier with {least,greatest}_index than with the
synonyms {min,max}, since I always think that the latter mean
least/greatest *element*, not index).
Thanks for the review.
Mark
More information about the reviews
mailing list