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

ArraySlice.foldli indices relative to the array instead of the slice #90

Closed
serpent7776 opened this issue Dec 3, 2021 · 2 comments
Closed
Assignees
Labels

Comments

@serpent7776
Copy link
Contributor

I get a different output running this code in mlkit v mlton:

let
  val arr = Array.fromList [1, 2, 3]
  val s = ArraySlice.slice (arr, 1, NONE)
in
  ArraySlice.foldli (fn (idx, elem, acc) =>
    (print (Int.toString idx); acc)
  ) 0 s
end;

mlton outputs 01
mlkit outputs 12

I believe this is a bug in mlkit, since ArraySlice.foldi doc states that The more general functions foldli and foldri supply f with the index of the corresponding element in the slice.

As I understand it, indices should be relative to the start of the slice, not the array. So index 0 should be the first element of the slice, not the first element of the array.

@melsman melsman self-assigned this Jan 17, 2022
@melsman melsman added the bug label Jan 17, 2022
@melsman
Copy link
Owner

melsman commented Jan 18, 2022

Interestingly, also the tests were wrong! It turns out that also MosML outputs 12. I suspect changes were made to the SML Basis Library specification after Peter Sestoft implemented the library functions (and tests) in MosML, which is where the MLKit library function implementations come from. The functions (and tests) have now been changed to match the SML Basis Library specification.

Ken (@kfl): Any comments?

@melsman melsman closed this as completed Jan 18, 2022
@kfl
Copy link
Contributor

kfl commented Jan 18, 2022

I think you are right Martin.

When Peter (@sestoft) implemented the *Slice modules 22 years ago, it was a refactoring of the Array module (and others) and the various old foldli functions and friends gave an index wrt the underlying array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants