What if these were real, type-safe expressions in Java:
2025 July 19 // → LocalDate
300M m/s // → Velocity
1 to 10 // → Range<Int>
Schedule Alice Tues 3pm // → CalendarEvent
That's the idea behind binding expressions — a compiler plugin I built to explore what it would mean if adjacency had operator semantics. It lets adjacent expressions bind based on their static types, forming new expressions through type-directed resolution.
Mathematica has Infix [0], which expresses the adjacency with a ~ (because Mathematica reserves pure blankspace for multiplication). But it works fine to do eg. `"hello"~StringJoin~" world"`; I was always surprised we could only have the predefined operators in many other languages and we couldn't define our own.
This seems like a great attempt. I would be worried about how much parsing and backtracking might be required to infer the infix precedence in a totally general system (like garden-path sentences[1]) or actually ambiguous parse trees (which is cured by adopting some rule like right precedence and parens, but what rule you pick makes some 'natural language' constructions work over others).
Sorry for this sounds absurd, but with diffusion language models, who generate text non-linearly (from the few that I get, they relate terms without a simpler order), I wonder if new syntactic ideas will come up.
The drawback is that building an AST now requires a symbol table and resolving imports, possibly performing type inference and whatnot. It constitutes a higher barrier for various types of tooling. You really want your programming language to avoid becoming context-sensitive in that way.
It’s similar for the human reader: The examples are only intelligible to the reader incidentally, due to the names used and some natural-text conventions. In the general case, you have a seemingly random token sequence where you have no idea what binds to what, without looking up the type definitions or having an IDE present the expression in some structured way again.
Furthermore, in typical code you don’t have the case of constant values so often. You’ll rather have things like:
nextYear thisMonth.previous() lastDayOf(thisMonth.previous())
Double.parse(speedInput) m/s
startPos to (startPos + length - 1)
Schedule contacts.select(contactId) inputForm.getDateTime()
I don't think this is useful in complex situations/expressions. Structure has to be encoded in the same place as meaning somehow. Natural language does it by using an extraordinarily large set of signifiers. That's not feasible for a formal language.
You could of course affix all lemmata with structural
information, as free word order languages do, but that's introducing syntactic structure via the backdoor.
An old paper on the expressiveness of the programming languages [1] had to add an implicit binary operator into whitespace to make Haskell not be ten times more expressive than most imperative languages.
So, yes, it can be done and it was done. Yes, expressiveness rises. No, reading comprehension of such languages does not suffer. Yes, it has to have a lot of scaffolding.
Information that might be of interest to someone here:
The formal name for the “empty” binary infix operator that gets implied in the AST when doing this, is the “juxtaposition” (or “juxtapose”, or “juxt”) operator. The implicit multiplication operator between `3` and `a` in the polynomial expression `3a + 4`, and the implicit function-application operator in the Lambda-calculus expression `f x y`, are both instances of an implied juxtaposition operator (with different semantics for it in each of the two cases, as befits each type of algebra/calculus.)
Yes, the empty infix operator is often called the "juxt" operator, which is an apt term here.
However, I use the term "binding expressions" intentionally because there’s more going on than ordinary juxtaposition. In a normal juxt expression such as:
a b c
the evaluation order is static and independent of the type system:
(a b) c
With binding expressions the precedence is type-directed, so the type system determines which grouping is valid:
(a b) c
a (b c)
Additionally, the operation itself can be provided by either operand. For a given expression a b, the compiler may resolve it as:
a.prefixBind(b)
b.postfixBind(a)
For example:
10kg
Here kg is a MassUnit, and MassUnit defines postfixBind(Number) returning Mass, so given there is no left-to-right binding, the expression resolves right-to-left as:
kg.postfixBind(10)
So while juxtaposition is the syntactic surface, the semantics are type-directed binding.
How is this different from backtracking? You're doing a depth-first search over possible interpretations. The grammar is just expressed in the type system instead of usual spec formats.
Critiques in other comments are accurate. This is a tooling nightmare, but also probably a nightmare to read. Consider an expression like
2026 March 10 to 13
What's the binding precedence? Does this mean March 10 through March 13, or midnight to 1 PM on March 10th? I think this breaks down outside of trivial examples that are better achieved in other ways.
Bjarne Stroustrup wrote a paper about adding overloading for the "whitespace operator" in C++, but in his case it was a joke: https://stroustrup.com/whitespace98.pdf
15 comments
[ 9.5 ms ] story [ 34.2 ms ] threadDetails here: https://github.com/manifold-systems/manifold/blob/master/doc...
This seems like a great attempt. I would be worried about how much parsing and backtracking might be required to infer the infix precedence in a totally general system (like garden-path sentences[1]) or actually ambiguous parse trees (which is cured by adopting some rule like right precedence and parens, but what rule you pick makes some 'natural language' constructions work over others).
[0] https://reference.wolfram.com/language/ref/Infix.html
[1] https://en.wikipedia.org/wiki/Garden-path_sentence
It’s similar for the human reader: The examples are only intelligible to the reader incidentally, due to the names used and some natural-text conventions. In the general case, you have a seemingly random token sequence where you have no idea what binds to what, without looking up the type definitions or having an IDE present the expression in some structured way again.
Furthermore, in typical code you don’t have the case of constant values so often. You’ll rather have things like:
You could of course affix all lemmata with structural information, as free word order languages do, but that's introducing syntactic structure via the backdoor.
[1] https://www.researchgate.net/publication/2743686_Are_Ours_Re...
So, yes, it can be done and it was done. Yes, expressiveness rises. No, reading comprehension of such languages does not suffer. Yes, it has to have a lot of scaffolding.
The formal name for the “empty” binary infix operator that gets implied in the AST when doing this, is the “juxtaposition” (or “juxtapose”, or “juxt”) operator. The implicit multiplication operator between `3` and `a` in the polynomial expression `3a + 4`, and the implicit function-application operator in the Lambda-calculus expression `f x y`, are both instances of an implied juxtaposition operator (with different semantics for it in each of the two cases, as befits each type of algebra/calculus.)
However, I use the term "binding expressions" intentionally because there’s more going on than ordinary juxtaposition. In a normal juxt expression such as:
the evaluation order is static and independent of the type system: With binding expressions the precedence is type-directed, so the type system determines which grouping is valid: Additionally, the operation itself can be provided by either operand. For a given expression a b, the compiler may resolve it as: For example: Here kg is a MassUnit, and MassUnit defines postfixBind(Number) returning Mass, so given there is no left-to-right binding, the expression resolves right-to-left as: So while juxtaposition is the syntactic surface, the semantics are type-directed binding.How is this different from backtracking? You're doing a depth-first search over possible interpretations. The grammar is just expressed in the type system instead of usual spec formats.
Critiques in other comments are accurate. This is a tooling nightmare, but also probably a nightmare to read. Consider an expression like
What's the binding precedence? Does this mean March 10 through March 13, or midnight to 1 PM on March 10th? I think this breaks down outside of trivial examples that are better achieved in other ways.