r/ProgrammingLanguages • • Apr 16 '26

Discussion Combining prefix and postfix function application concrete syntax

I am just thinking about how syntax would work if you took a symmetric approach to function application syntax where prefix and postfix application are both allowed at the same time for any function. Let me know your thoughts on this syntax!

I distinguish between 2 orthogonal axes, a fixity axis is (prefix < and postfix >), and an associativity axis (left 1 and right 2 associative). The direction of the inequality is the direction in which the argument is fed into the function so f < x and x > f for feeding x into f.

< means prefix and left associative

<< means prefix and right associative

> means postfix and left associative

>> means postfix and right associative

For the examples below, I define how these operators work by converting the operator into an abstract syntax AP(f, x) operator meaning function f is applied to input x. AP is strictly prefix with parenthesized arguments to be fully unambiguous. f, g, h ... range over functions. a, b, c, ... range over expressions of any type.

Curried application: f < a < b == b >> a >> f == AP(AP(f, a), b)

Composition/Pipelining: a > f > g == g << f << a == AP(g, AP(f, a))

I think it would be logical to bias left associativity with either fixity because naturally we read left to right, and so this ordering makes sense.

For curried application f a b c d e ... prefix notation makes a lot of sense because the successive arguments are fed into the function from left to right order. f : A -> B -> C -> D -> ... and a : A, b : B, ...

With function composition in a lot of functional languages and in category theory we take (Haskell) g $ f a to mean a : A => f : A -> B => g : B -> C. The standard ordering g f x is a bad ordering because chronologically you start with x, and then f goes first and then g, but with my syntax the pipelining/function composition would be nice and chronological a > f > g. Meanwhile alternative right associative ordering is still available but not as prioritized.

In general a : A, f : A -> B, g : B -> C, h : C -> D, i : D -> E, ....

I believe (?) that this combined prefix and postfix application should be unambiguous. Just make < and > have greater precedence than << and >>, so for example A < B >> C == (A < B) >> C. Combining < and > is fine because they both associate to the left, and same for << and >>.

5 Upvotes

17 comments sorted by

View all comments

Show parent comment

1

u/FlamingBudder Apr 16 '26

Yeah you could/maybe should do that, and explore some of the 4! = 16 different permutations of symbols, or switch up the symbols to make the behavior more intuitive. Let me know if you find something that is nice, intuitive, readable, and other good qualities!