Skip to content

feat(analyser): type tuples of any length with spread type parameters 🧩 - #572

Merged
timfennis merged 1 commit into
masterfrom
feature/variadic-tuple-types
Nov 29, 2026
Merged

timfennis merged 1 commit into
masterfrom
feature/variadic-tuple-types

Conversation

@timfennis

Copy link
Copy Markdown
Owner

A built-in's signature couldn't say "a tuple of any length", so len, first, last and the comparisons had one overload per tuple length up to twelve, and longer tuples were rejected (#344, #403). This is also the first step towards typing tuple concatenation with ++ (#296).

What changes:

  • A signature can declare a type parameter ..R, which stands for a tuple type, and spread it into a tuple: len is <..A>((..A)) -> Int, first is <A, ..R>((A, ..R)) -> A, last is <..R, A>((..R, A)) -> A, and < takes <..A>((..A), (..A)). They take tuples of any length, and the per-length overloads are gone.
  • A tuple among the parameters takes at most one spread, so the arguments say what each one is. A return type may spread several, as (..A, ..B).
  • A call waits until the argument at a spread is a tuple, as it would if there were one overload per length. After that, the signature is matched like any other.
  • A type argument for a spread parameter is a tuple type: len::<(Int, String)>((1, "a")).
  • ndc docs and hover show such a parameter as ..R.
  • zip keeps one overload per number of sequences, up to twelve: spreading parameter lists isn't part of this.

Closes #344, closes #403.

Written with AI (Claude Code), all of it.

🤖 Generated with Claude Code

Co-authored-by: Claude Opus 5.5 noreply@anthropic.com

A built-in's signature can declare a type parameter `..R` that stands
for a tuple type and spread it into a tuple, as in
`<A, ..R>((A, ..R)) -> A`. A tuple among the parameters takes at most
one spread, so a call's arguments say what each is. `len`, `first`,
`last` and the comparisons take tuples of any length with one
signature each instead of one per length up to twelve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T15:08:34.253617Z 9f8f61c PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 9f8f61c81a

ℹ️ 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".

parameters: Some(vec![StaticType::unit()]),
return_type: Box::new(StaticType::Int),
},
"<..A>((..A)) -> Int",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the tuple manual for the changed built-in signatures

The public tuple API now accepts arbitrary tuple lengths and uses tuple-valued explicit type arguments, such as len::<(Int, String)>((1, "a")), but this commit does not update any manual page. Add the relevant explanation and a runnable example to manual/src/reference/types/tuple.md so users can discover the supported behavior and type-argument syntax. The root AGENTS.md explicitly requires updating the relevant manual page when language behavior changes.

AGENTS.md reference: AGENTS.md:L99-L99

Useful? React with 👍 / 👎.

@timfennis
timfennis merged commit 2c11a18 into master Nov 29, 2026
1 check passed
@timfennis
timfennis deleted the feature/variadic-tuple-types branch November 29, 2026 18:39
timfennis added a commit that referenced this pull request Nov 29, 2026
The manual documented both meanings of `++` on tuples: concatenation,
which the type checker rejected, and applying `++` to each pair of
elements. #296 settled on concatenation, which #572 made possible to
type.

What changes:
- `(1, "a") ++ (2.5, true)` is `(1, "a", 2.5, true)`, a `(Int, String,
Float, Bool)`, through one native typed `<..A, ..B>((..A), (..B)) ->
(..A, ..B)`. `("a", "b") ++ ("c", "d")` is `("a", "b", "c", "d")`, no
longer `("ac", "bd")`. Other operators still apply to each pair of
elements.
- `++` takes tuples whole, as the comparisons do: `("a", "b") ++ "c"`
and `([1], [2]) ++= [3]` are type errors now instead of applying `++` to
each element.
- `t ++= (4, 5)` is an error for a non-empty right side, as it gives the
variable a tuple of another length, which is another type. The error
says so.
- The manual's tuple page shows `++` with the other tuple operators and
drops it from the element-wise examples. The tests of element-wise
operators that used `++`, including per-position overloads and in-place
`op=`, use `|` on sets, maps, Ints and Bools now.

Closes #296.

Written with AI (Claude Code), all of it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

Compare tuples longer than twelve elements A tuple pattern for built-in signatures

1 participant