r/ProgrammingLanguages • u/FlamingBudder • 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 >>.
View all comments
Show parent comment
1
u/FlamingBudder Apr 16 '26
I'm not completely sure precisely what your notation of b(...) is so I'll assume that means b is a function which has a "hole", or the "input" that you can put an argument into. I will use the notation f(x)(y)(z) to be curried application. And I will try using your (...) notation too but I might be misinterpreting what you mean.
(a < b) < c ==> a(b) < c ==> a(b)(c)
(a(...) < b) < c ==> (a(b))(...) < c ==> a(b)(c)
Apply a to b, then take the result (it must be a function) and apply it to c. In this case b and c can be any value. It could be a function, it could be just a non-function value. We are putting b into a, taking what A produces (which must be some sort of function) and then putting c into it. c also does not have to be a function.
The other case looks very different
a < (b < c) ==> a < b(c) ==> a(b(c))
a(...) < (b(...) < c) ==> a(...) < b(c) ==> a(b(c))
Below I give a concrete example, which might help a bit