Ticket #224 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

expression-level type annotations

Reported by: dherman Assigned to: anonymous
Type: enhancement Priority: major
Milestone: Component: Proposals
Version: 4 Keywords:
Cc:

Description

Suggested by Phil Wadler: add an expression-level type annotation operator:

Expression ::= ... | (Expression : Type)

so that programmers can write type assertions not just on bindings but arbitrary expressions. This creates a nice parallel to the "wrap" syntax so that programmers can gradually introduce tighter type invariants on their code.

For example, version 1 of a program might look like:

function f() : * { ... }
...
let x : int = (f() wrap int)

But then when you add type annotations to f, version two simply changes the "wrap" to a ":" annotation:

function f() : int { ... }
...
let x : int = (f() : int)

Phil also suggested both operators have similar syntax, in particular with the same column width, to minimize the cost of changing the annotation, for example ":" for type-constrain and "@" for wrap. Then the migration becomes a one-character fix, and doesn't disturb your program's indentation/line-breaking levels.

Attachments

Change History

Changed 1 year ago by dherman

Lars and Jeff pointed out that "cast" already fulfills this requirement exactly.

Changed 1 year ago by dherman

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.