Skip to content

Proposal: expose tuple type declarations #4335

@fengb

Description

@fengb

We now have anonymous tuples, but they can only be created at runtime using the var type. While this satisfies "varargs" and coercion to arrays / vectors, we still cannot define a tuple type at comptime.

Potential syntax:

const Point = tuple{ i32, u32 }; // explicit, but adds a keyword
const Point = struct{ @"0": i32, @"1": u32 }; // matches the backend structure but feels pretty gross

Packed tuples should also be possible since it can represent in memory data structures pretty well, like manually managed stacks.

Accepted syntax

Per #4335 (comment):

const Point = struct{ i32, u32 };

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions