Skip to content

DDIR: enum declares sums, and type declares erased aliases - #1087

Merged
frankmcsherry merged 2 commits into
TimelyDataflow:master-nextfrom
frankmcsherry:ddir-enum-type
Nov 13, 2026
Merged

frankmcsherry merged 2 commits into
TimelyDataflow:master-nextfrom
frankmcsherry:ddir-enum-type

Conversation

@frankmcsherry

Copy link
Copy Markdown
Member

enum now declares sums and type declares aliases, so type Text = List(int); and type Pair = (int, int); name structural shapes.
A draft: the change is complete and tested; aliases inside lambdas wait on a corgi change.

The language

enum Member = User int | Group int;   -- a sum, with the variant syntax `type` used before
enum Node = Node List(int);           -- a one-variant sum needs no special form
type Text = List(int);                -- an alias
type Grant = (Member, Text);          -- aliases may name enums and other aliases
let grants = input 0 : (int, Grant);
  • An alias resolves to its shape wherever a declared name may appear: input, import, var and output declarations, and enum payloads.
  • Enums are structural: variant names are for reading and erase, so two enums with the same lane shapes are the same type. The README says so.
  • Enums and aliases share one namespace and may be declared in any order. A cycle through either kind is an error, as is a duplicate name.
  • type X = A | B; fails with "sums are declared with enum, not type". The old spelling is not kept.
  • enum matches the text corgi already uses for sums (enum Name = … in … inside lambdas, and DDIR's declarations to corgi's Scope).

Inside lambdas

Lambda ascriptions such as (x : Text) are parsed by corgi, which has no aliases.
For now they fail with unknown enum 'Text'; alias `Text`: aliases are not yet available inside lambdas.
A corgi draft adds type Name = shape to corgi (frankmcsherry/WIP#149); a DDIR follow-up that hands aliases to corgi is tested against it and waits on moving DDIR's corgi pin.

Conversion and checks

  • 34 files: 13 programs, 13 plan-pair snapshots, 7 Rust files and the README. Every declaration needed only the keyword, including the one-variant sums in binders.ddp and join_fallback.ddp.
  • The regenerated snapshots differ only in the keyword.
  • Six new tests: aliases in shapes and chains, aliases of enums and enum payloads naming aliases, alias and mixed cycles, duplicate names, the enum hint, the lambda error, and inline corgi enums.
  • cargo test --release -p interactive passes; all nine example .expected outputs match at 1 to 4 workers.

Implemented by GPT-6 Sol (Codex); reviewed, tested and opened by Claude Code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H6wB4H99TLw4tqu4x48pXL

frankmcsherry and others added 2 commits November 13, 2026 16:45
`enum Name = V0 shape? | V1 shape? | …;` declares a sum, with the variant syntax `type` used before.
`type Name = shape;` now declares an alias, which resolves to its shape wherever a declared name may appear: input, import, var and output declarations, and enum payloads.
Enums stay structural, and aliases erase, so the language stays structurally typed.
Enums and aliases share one namespace, may refer to each other in any order, and a cycle through either is an error.
`type X = A | B;` is an error that points to `enum`.

An alias inside a lambda fails with a message saying aliases are not yet available there, because corgi parses lambda ascriptions and has no aliases.

Every sum declaration, the plan printer, the language reference and the README use `enum`, and the plan-pair snapshots are regenerated; they differ only in the keyword.

Co-Authored-By: GPT-6 Sol (Codex) <noreply@openai.com>
Claude-Session: https://claude.ai/code/session_01H6wB4H99TLw4tqu4x48pXL
… at `enum`

`type int = float;` was accepted and ignored, since `int` resolves before declared names.
Declaring `int`, `float`, `List`, `Option` or `Result` as an enum or an alias is now an error.
An alias must be one shape followed by `;`, so `type Node = Node List(int);` now gets the hint that sums are declared with `enum`, rather than "Expected Semi".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H6wB4H99TLw4tqu4x48pXL
@frankmcsherry
frankmcsherry marked this pull request as ready for review November 13, 2026 22:36
@frankmcsherry
frankmcsherry merged commit 59d0bdd into TimelyDataflow:master-next Nov 13, 2026
7 checks passed
frankmcsherry added a commit that referenced this pull request Nov 14, 2026
#1088's new test declared `type Member = User int | Group int;`, written before #1087 made `type` an alias and `enum` the sum declaration.
The two merged separately, so master-next failed two tests in `tests/flatmap.rs`.


Claude-Session: https://claude.ai/code/session_01H6wB4H99TLw4tqu4x48pXL

Co-authored-by: Claude Opus 5.5 (1M context) <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.

1 participant