Skip to content

Additions to the standard library#848

Open
TimWhiting wants to merge 1 commit intokoka-lang:devfrom
TimWhiting:std-library-additions
Open

Additions to the standard library#848
TimWhiting wants to merge 1 commit intokoka-lang:devfrom
TimWhiting:std-library-additions

Conversation

@TimWhiting
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings December 6, 2025 04:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a comprehensive set of utility functions to the Koka standard library for both vectors and lists, enhancing functional programming capabilities.

Key Changes:

  • Added vector operations including folding (foldl, foldr), zipping (zip, zip-with, zip-with-indexed), and collection manipulation (take, drop, slice, reverse, append)
  • Introduced predicate/equality-based overloads for list functions using namespace prefixes (pred/ and eq/)
  • Added missing comparison operators for ssize_t type (==, !=, >)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
lib/std/core/vector.kk Adds functional programming utilities (fold, zip, map-indexed), collection manipulation functions (take, drop, slice, reverse, append), equality operators, and additional ssize_t comparison operators
lib/std/core/list.kk Refactors existing functions with namespace prefixes (pred/, eq/) and adds equality-based variants (contains, eq/remove, eq/lookup, eq/index-of) with improved parameter destructuring

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/std/core/vector.kk
Comment thread lib/std/core/vector.kk Outdated
Comment thread lib/std/core/list.kk
Comment on lines +402 to +406
pub fun eq/index-of( xs : list<a>, value : a, ?(==) : (a,a) -> e bool ) : e maybe<int>
fun recur( ys, idx )
match ys
Cons(y,yy) -> if y==value then Just(idx) else recur(yy,idx+1)
Nil -> Nothing
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The return type is inconsistent with pred/index-of which returns int (with -1 for not found). This function returns maybe<int>, which creates an inconsistency in the API. Consider either returning int with -1 for consistency, or updating both functions to use maybe<int>.

Suggested change
pub fun eq/index-of( xs : list<a>, value : a, ?(==) : (a,a) -> e bool ) : e maybe<int>
fun recur( ys, idx )
match ys
Cons(y,yy) -> if y==value then Just(idx) else recur(yy,idx+1)
Nil -> Nothing
pub fun eq/index-of( xs : list<a>, value : a, ?(==) : (a,a) -> e bool ) : e int
fun recur( ys, idx )
match ys
Cons(y,yy) -> if y==value then idx else recur(yy,idx+1)
Nil -> -1

Copilot uses AI. Check for mistakes.
Comment thread lib/std/core/list.kk Outdated
Comment thread lib/std/core/vector.kk
unsafe-assign(w,i + l1,v2.unsafe-idx(i))
w

// Append two vectors
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The documentation comment "Append two vectors" is duplicated from the append function above (line 274). This should describe that it's an operator alias for append or reference the append function.

Suggested change
// Append two vectors
// Operator alias for `append`: append two vectors.

Copilot uses AI. Check for mistakes.
Comment thread lib/std/core/vector.kk
@TimWhiting TimWhiting force-pushed the std-library-additions branch 2 times, most recently from 237feda to eb4d604 Compare December 6, 2025 04:41
@TimWhiting TimWhiting force-pushed the std-library-additions branch from eb4d604 to 52881c8 Compare December 6, 2025 04:43
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