haskelloperator-precedenceconcatenative-languagepolish-notation

Making a concatenative Haskell variant: precedence of application and composition


I'm learning the basics of concatenative languages, whose original idea is that function name concatenation is the same as function composition, instead of being function application as in Haskell.

Joy, Forth or Factor are postfix, which means stack based, but there are some prefix concatenative languages as well, such as Om.

I wonder if a Haskell variant could theoretically be a concatenative language just by swapping (or even equaling) the composition precedence (now 9) with the function application precedence (now 10).

If values in Haskell are just zero-argument functions, why is function application different than function composition?, is not function application the same as composing with a zero-argument function?.

Would it be possible in a simple way to make an interpreter or precompiler which transforms concatenative syntax to Haskell syntax by defining new composition and application operators with different precedence, and assuming that simple concatenation without parenthesis is composition?. I think that it is just a question of syntax, am I wrong?, and it would avoid many of the cases where we have to use parenthesis or $ operator in Haskell. Or is it a more fundamental problem, not just syntax and precedence?

Hint: suppose that every function and operator in Haskell is prefix, we can forget for this exercise about infix notation and all kinds of "syntactic sugar".


Solution

  • The best answer for my question is the article referenced by @Daniel Wagner on his second comment, "Concatenative, Row-polymorphic Programming in Haskell", which was written by Sami Hangaslammi as an answer to another good article by @Jon Purdy, "Why Concatenative Programming Matters".

    It shows "one way to implement a concatenative DSL inside Haskell", which is what I really wanted to know if it was possible, and how.