Flattening Combinators: Surviving Without Parentheses [pdf](westpoint.edu)
westpoint.edu
Flattening Combinators: Surviving Without Parentheses [pdf]
http://www.westpoint.edu/eecs/SiteAssets/SitePages/Faculty%20Publication%20Documents/Okasaki/jfp03flat.pdf
10 comments
Related to this: Brent Kerby and Billy Tanksley devise flat, two-combinator bases for Turing-complete concatenative languages. Kerby's is at https://groups.yahoo.com/neo/groups/concatenative/conversati... and Tanksley's follows a few posts later.
Oh cool! This immediately made me think of Joy.
I started to use OCaml again and I noticed that they recently introduced the operator "|>". It lets you write things like "2 + 3 |> print_int" instead of "print_int (2 + 3)" or "let x = 2 + 3 in print_int x". It's particularly convenient for longer nested expressions.
Once you know that trick, it's tempting to use it everywhere and avoid parenthesis as much as possible. I'm not sure what the accepted practice is though as it doesn't always improve readability.
I also wonder why it took so long before they introduced it in the language. It's so simple and convenient. Did it take decades of people writing ML before someone thought of this?
Once you know that trick, it's tempting to use it everywhere and avoid parenthesis as much as possible. I'm not sure what the accepted practice is though as it doesn't always improve readability.
I also wonder why it took so long before they introduced it in the language. It's so simple and convenient. Did it take decades of people writing ML before someone thought of this?
I believe the |> operator has been around for a while -- I've seen it used in some older Standard ML code, but just as a user-defined operator and not part of the basis library. F# included it in the core library for the language and it was fairly popular there for structuring heavily-nested expressions into a more-human-readable "pipeline". OCaml added it to the Core library fairly recently, as has (I believe) Elixir.
Ocaml has had the @@ operator for a while, which is |> with it's arguements inversed, so you could write "print_int(2+3)" or "print_int @@ 2+3". Haskell is in a similar place, with the $ operator (equivalent to @@), but no |> in the standard library [0]. The main issue is that for a lot of people, there just isn't that much of a benefit to composing function left to right, as apposed to right to left; especially since the "simple" way of just using parentheses gives us right to left composition.
[0] If you want this, check out the flow package https://hackage.haskell.org/package/flow-1.0.8/docs/Flow.htm...
[0] If you want this, check out the flow package https://hackage.haskell.org/package/flow-1.0.8/docs/Flow.htm...
My complaint with |> is that it makes code with nesting look quite different based on argument position. Argument position is not a very interesting property, so it doesn't seem right for it to be influencing the shape of code in that way.
My preference is to use parens and introduce single-shot variables if nesting gets too deep. This works the same way for all code.
My preference is to use parens and introduce single-shot variables if nesting gets too deep. This works the same way for all code.
TIL Chris Okasaki works for West Point.
Okasaki really is brilliant
Delightful!