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

Specific List functions can accept 0 elements #2351

Merged
merged 1 commit into from Oct 29, 2023

Conversation

OAGr
Copy link
Contributor

@OAGr OAGr commented Oct 25, 2023

Number.sum, product, sort, cumsum, cumprod, should all accept lists with 0 elements

This closes #2349

@OAGr OAGr requested a review from berekuk as a code owner October 25, 2023 19:06
@changeset-bot
Copy link

changeset-bot bot commented Oct 25, 2023

🦋 Changeset detected

Latest commit: 85d81c8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@quri/squiggle-lang Patch
@quri/squiggle-components Patch
@quri/prettier-plugin-squiggle Patch
vscode-squiggle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@OAGr OAGr temporarily deployed to Preview October 25, 2023 19:07 — with GitHub Actions Inactive
@vercel
Copy link

vercel bot commented Oct 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 7:11pm
quri-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 7:11pm
squiggle-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 25, 2023 7:11pm
squiggle-website ✅ Ready (Inspect) Visit Preview Oct 25, 2023 7:11pm

@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (20b52b9) 71.65% compared to head (88ae8af) 71.66%.
Report is 2 commits behind head on main.

❗ Current head 88ae8af differs from pull request most recent head 85d81c8. Consider uploading reports for the commit 85d81c8 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2351   +/-   ##
=======================================
  Coverage   71.65%   71.66%           
=======================================
  Files         111      111           
  Lines        5704     5706    +2     
  Branches     1091     1093    +2     
=======================================
+ Hits         4087     4089    +2     
  Misses       1610     1610           
  Partials        7        7           

see 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@berekuk berekuk left a comment

Choose a reason for hiding this comment

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

For sum and product, there's a slight risk that in the future we'll have to deal with ambiguity because of polymorphism: we could decide to add sum(string[]) or sum(dist[]), and then the result of sum([]) becomes unclear.

This could be bad if the array is generated dynamically, and especially because of interactions with the type inference and compile-time polymorphic dispatch.

Consider this code:

sumArrays(arrs) = arrs -> map({|arr| sum(arr)})

sumArrays([
  ["foo", "bar"],
  []  // imagine that this was obtained by calling another function that does `filter` at runtime
])

Now, if sum is polymorphic, but we also have sum([]) defined to be 0, then the result of sumArrays will be either ["foobar", 0] or ["foobar", ""].

["foobar", ""] result could happen in this case if the interpreter would detect that sumArrays accepts an array of arrays of strings, and so every sum call is over an array of strings.

So it's going to be a minor breaking change, when/if we get there.

@berekuk berekuk merged commit 214c4f0 into main Oct 29, 2023
8 checks passed
@berekuk berekuk deleted the list-methods-allow-empty-lists branch October 29, 2023 05:53
@github-actions github-actions bot mentioned this pull request Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

List.sum() and similar should work for empty lists
2 participants