Let's say I want to allow (conservative) let bindings, with optional type ascription. Most imperative languages would put a = or := after the identifier, but wouldn't omitting the assignment operator work? Like this:

let <ident>[:<type>] <expr>;

Tuple assignments or record destructuring are also delimited

let { a, b, c } some_values();

My question: Is there any way that omitting the assignment operator as shown causes the let binding to be ambiguous?

I'm aware that languages like OCaml have a more powerful let binding syntax (like let func arg1 arg2 = ...), so I'm mostly talking about simpler implementations like Swift, Rust or Typescript.

  • 5
    $\begingroup$ The answer could be yes or no, depending on the syntax your language uses. Without a detailed specification of that syntax, we can't really answer. And if you did provide a detailed specification, this wouldn't be a very good question, as it wouldn't really be useful to anyone except you. $\endgroup$
    – pxeger
    Jul 9, 2023 at 13:01

1 Answer 1


You'd want to consider the interaction of possible keyword prefix operators for both types and expressions. For example:

let x: a b c

If you have a prefix a type operator (like readonly in TS), then the value is c. If you don't, but have a b prefix value operator (like void in JS), then the value is b c. If you have both then there's a potential ambiguity.

Obviously this would also apply to postfix keyword operators but I'm not aware of any of those offhand.

  • $\begingroup$ F# has postfix type operators, e.g. int list. I think they're common in ML-family languages. $\endgroup$
    – kaya3
    Jul 24, 2023 at 12:16

You must log in to answer this question.