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 edited Apr 17 '26
Thanks for sharing all this! I very briefly looked at some of the papers, and the one I was able to understand quickly was De Brujin's notation, which was very cool. Is there a parser that can convert between standard LC notation and De Brujin's notation/other variations too? If not, I think I'll play around with it and maybe create some sort of translator and parser or even a step-through evaluator. I think it would be cool to see some non-trivial programs with this notation. I think it would also be interesting to look into the co-DeBrujin LC which is prefix. The notation would be exactly the same order as Haskell's where clause
Overall though, I think you can go about syntax in 2 directions:
I'm not sure though, I am quite naive in this field so there might be things I'm missing.