▲ | wk_end 11 hours ago | |||||||||||||||||||||||||||||||||||||||||||||||||
The title is a little inflammatory. The critique is specifically about Ocaml’s handling of let-bindings. AFAICT OP thinks the syntax sucks because: 1. there’s no marker to indicate the end of let scopes 2. functions are bound with the same syntax as constants He asserts that this is confusing. In practice - for the many issues I have with Ocaml! - neither of these are actual issues, in my experience, once code formatting is applied. An actual serious problem with Ocaml’s syntax is that matches don’t have a terminator, leading people to mess up nested matches frequently. Pair that with the parser’s poor error reporting/recovery and things can become unpleasant quickly. | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | sevensor 18 minutes ago | parent | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
> The title is a little inflammatory. Xah Lee is not exactly known for moderation. If you’re not familiar, browsing the site may be worth your while. It’s full of inflammatory and sometimes bizarre takes, but I’d be hard pressed to argue that it’s ill informed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | p4bl0 6 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
I was coming to say exactly this. I use OCaml a lot and never had a problem with lets. On the other hand, nested match with where you must either use parentheses or begin…end can be confusing for beginners and stays annoying forever. | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | nine_k 11 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
Fortunately, the OCaml compiler is very modular, and there have been efforts to make things more... reasonable. - Reason, a different syntactic frontend for regular OCaml: https://reasonml.github.io/ - ReScript, a language with OCaml semantics that compiles into: JS https://rescript-lang.org/ (I suppose it's a reincarnation of js-of-ocaml). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | soraminazuki 7 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
> The title is a little inflammatory I think you’re being generous. The example the author gave is awful because any language can be made illegible if you cram in complicated expressions with multiple levels of nesting into a single line. I’d say it’s outright flamebait. | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | pyrale 7 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
> functions are bound with the same syntax as constants Apparently, the author hasn't come around to understanding that functions are just another constant. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | RandomThoughts3 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
> An actual serious problem with Ocaml’s syntax is that matches don’t have a terminator, leading people to mess up nested matches frequently. Pair that with the parser’s poor error reporting/recovery and things can become unpleasant quickly. Yes, it's clearly one of the syntax weak point. You can surround them with parentheses or begin ... end to make things explicit but the default is definitely error prone. | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | yodsanklai 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
> leading people to mess up nested matches frequently. Very often this leads to typing errors. Otherwise it's caught by autoformat (which everyone should be using). But even without that, this is one pitfall every OCaml developer is aware of. I'm not arguing the syntax is perfect, but I wouldn't say it has a serious problem because of that. Never seen that being a problem. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | remexre 8 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
i agree an autoformatter alleviates the let decl/expr in practice, especially for an experienced user; an autoformatter also fixes nested matches too ime. however, my university has a mandatory class taught in ocaml, which i've ta'd for a few times; this is the _number one_ "the undergrad ta couldn't figure out my syntax error" issue students have | ||||||||||||||||||||||||||||||||||||||||||||||||||
▲ | seanhunter 9 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||||||||||||||||||||
Totally agree. In particular when I read #2 I was really scratching my head. It's a functional language - the thing on the left of the equals sign is a pattern. Apart from the argument you pass, patterns for functions look similar to patterns for constants precisely because in a functional language everything looks like a function. And everything looks like a function because just about everything is a function. The match terminator end thing made me sad when I first saw this in Ocaml. So many languages (C, bourne shell, etc etc) have this exact same problem and it completely sucks in all of them. It's more debilitating in a functional language specifically because matches are more useful than say C case statements so you want to use them much more extensively. I frequently want to do a pattern match to unpack something and then a further pattern match to unpack further - a nested match is a very intuitive thing to want. Yes you can normally unnest such a match into more complicated matches at the parent level but this is usually much harder for humans to understand. ...and if you had a marker for ending match scopes you could always just reuse that to end let scopes as well if you wanted to although I've literally never a single time run into that as a practical problem (although I haven't written that much OCaml you'd think if it was a real issue I would have banged into it at least once because I found a fair few sharp edges in my time with the language). |