Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arrayCopy, arraySet, arrayRangeEqual array primitives. #1268

Merged
merged 4 commits into from
Aug 25, 2021

Conversation

andreistefanescu
Copy link
Contributor

Add arrayRangeLookup and arrayRangeUpdate helpers.

lib/Array.cry Outdated
arrayRangeUpdate : {a, b, n} (Integral a, fin n, n >= 1, Literal (n - 1) a) => (Array a b) -> a -> [n]b -> (Array a b)
arrayRangeUpdate arr idx vals = arrs ! 0
where
arrs = [arr] # [ arrayUpdate acc (idx + i) val | acc <- arrs | i <- [0 .. (n - 1)] | val <- vals ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a small thing, but I think you could avoid the n >= 1 constraint if you used the i <- [ 0 ..< n ] enumeration form instead.

I think the n >= 1 constraint is also unnecessary for arrayRangeLookup.

lib/Array.cry Outdated
* Copy elements from the source array to the destination array.
*
* 'arrayCopy dest_arr dest_idx src_arr src_idx len' copies the
* elements from 'src_arr' at indices '[src_idx .. (src_idx + len)]' into
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to nitpick some more, but I think essentially all these ranges are intended to be half-open and we should probably use the Cryptol-style notation for that, which would make this [src_idx ..< (src_idx + len)], and similar below.

Copy link
Contributor

@robdockins robdockins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix up the failing regression test case and address the comment nitpicks. Then I think this is good to go.

@andreistefanescu andreistefanescu merged commit 052228e into master Aug 25, 2021
@andreistefanescu andreistefanescu deleted the array-copy-set branch August 25, 2021 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants