Skip to content

RFC: Lambda parameter type annotations syntax (lambda x: int: x + 1) #417

@antonsynd

Description

@antonsynd

Context

Identified during spec-test alignment audit (DIV-5). The lambda type annotation syntax creates a parsing ambiguity with the double-colon problem.

Current behavior

Lambda expressions use the syntax lambda x: x + 1. If we want to add type annotations to lambda parameters (like lambda x: int: x + 1), the parser cannot distinguish between the type annotation colon and the body-start colon.

Expected/proposed

An RFC is needed to decide on a syntax for lambda type annotations that avoids the double-colon ambiguity. Possible approaches:

  • lambda (x: int): x + 1 — parenthesized parameters
  • lambda x as int: x + 1 — alternative annotation syntax
  • Require full def for typed lambdas — simplest but most restrictive
  • Reference the property syntax decision for consistency

This is a language design question that needs community input before implementation.

References

  • docs/language_specification/expressions.md — lambda expression syntax
  • docs/language_specification/type_system.md — type annotations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions