Skip to content

Align List membership APIs with Array - #8530

Open
cknitt wants to merge 3 commits into
masterfrom
list-includes
Open

Align List membership APIs with Array#8530
cknitt wants to merge 3 commits into
masterfrom
list-includes

Conversation

@cknitt

@cknitt cknitt commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Add List.includes for checking list membership using strict equality
  • Deprecate the comparator-based List.has API in favor of List.some
  • Correct the documented equality semantics of Array.includes
  • Add dedicated Stdlib_List tests covering:
    • present and missing values
    • empty lists
    • object reference identity
  • Add executable documentation covering the intentional NaN behavior

Motivation

The list and array APIs currently use inconsistent names for membership checks. Arrays expose the familiar some and includes APIs, while lists additionally expose the legacy comparator-based has.

Adding List.includes aligns the membership API names across lists and arrays. Deprecating List.has guides custom comparisons toward the existing predicate-based List.some API without breaking existing code.

The existing Array.includes documentation incorrectly described its JavaScript implementation as using strict equality. It actually uses SameValueZero equality.

Semantics

List.includes uses strict equality:

  • primitive values compare by value
  • object values compare by reference
  • NaN is not equal to itself

This intentionally keeps the list implementation simple.

Array.includes retains JavaScript’s native SameValueZero semantics, under which NaN is equal to itself. Its documentation now describes this distinction correctly.

let has: (list<'a>, 'b, ('a, 'b) => bool) => bool

/**
`includes(list, item)` checks whether `list` includes `item` using strict equality.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Which is different from Array.includes which uses SameValueZero equality, but I was unsure if the NaN edge case is worth complicating the implementation.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a6463d969

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/@rescript/runtime/Stdlib_Array.resi
Comment thread packages/@rescript/runtime/Stdlib_List.resi
@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8530

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8530

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8530

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8530

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8530

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8530

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8530

commit: fd23b01

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

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.

1 participant