RedPRL / ocaml-bwd

🔙 Backward lists for OCaml
https://ocaml.org/p/bwd
Apache License 2.0
19 stars 2 forks source link

Precedence of infix notation #12

Closed mikeshulman closed 1 year ago

mikeshulman commented 1 year ago

Why did you choose an infix notation whose precedence is higher than function application? It's contrary to all my intuitions for f x #< y to mean f (x #< y).

jonsterling commented 1 year ago

Wow! I did not realize that there was an operator with such a high precedence... I think we ought to change this. (Or, honestly, just remove the infix operator.)

favonia commented 1 year ago

I have been unhappy with the current symbols, but let me propose something before we throw all infix operators out. :smile_cat:

Advantages:

  1. Their precedence is lower than function application (addressing the current issue): https://v2.ocaml.org/manual/expr.html#ss%3Aprecedence-and-associativity
  2. <: and <@ are left-associative and @> is right-associative. Previously, <>> is wrongly left-associative, which means you cannot write b1 <>> b2 <>> .... The proposed replacement of <>>, @>, is correctly right-associative.
  3. Visually, <: is close to the built-in list "cons" :: and <@ and @> are close to the built-in list concatenation @. Directions of <@ and @> are clearer than those of <>< and <>>. As a consequence, <: (Snoc) and <@ (append) look more consistent and it's easy to remember <@ (append) and @> (prepend).