I personally tend to feel that the ReasonML project is a good thing for OCaml, because I do think that familiarity can strongly affect what languages programmers are willing to learn. I am happy using OCaml syntax, but when I think about recommending it to others, I feel that the traditional syntax will be an initial roadblock for some people. I also recognize that some things about traditional syntax that have puzzled me while learning (which I am still doing) might be clearer with Reason syntax. Whatever syntax I use, I appreciate all of the work that the ReasonML team and supporters have put into it.
All that said, I’m puzzled by one of the changes in the new syntax.
Old syntax:
let f x y => x + y
New syntax:
let f = (x, y) => x + y
I can understand why the parentheses-and-comma syntax for parameters makes sense–that’s what’s common in the world outside the ML/Haskell and Lisp domains. What is the purpose of the =
sign, though? Shouldn’t arguments be next to the function name?
I assume that there is some reason (really, no pun) for putting a character between the function name and the arguments–something about parsing or ambiguity–but I can’t figure out what it is. Given the goal of having a syntax that is more comfortable to people used to Javascript, Java, etc., the =
sign just seems weird. It adds a little wart, relative to what programmers are used to. So there must be a rationale for it.
Or here’s a thought: Is the idea that I’m supposed to read the function definition as grouped to the right, like
let f = ((x, y) => x + y)
? i.e. the =>
is an infix lambda
(Lisp) or function
(Javascript) or fun
(OCaml) or fn
(Clojure) or \
(Haskell)? That makes sense of the syntax, but to me it still seems like it’s going to confuse the folks that ReasonML syntax is supposed to attract. Latin-character languages read left to right. The prefix lambda operators make it clear that an anonymous function is beginning, so adding one of them at the beginning would help. Even requiring parentheses after the equals sign would help.
(The blog post introducing ReasonML 3 made a slightly disdainful comment about expected complaints about the new syntax. I know that every change in anything popular will bring complaints, and I support making improvements. Call this feedback, or call it simply a request for clarification, but it’s from a supporter of the ReasonML project. If the idea is that the ReasonML designers have no interest in what anyone else thinks, that could be a problem, but I assume that’s not the case. I am not against the BDFL-style model of language control, either–it’s a great model when it works.)