Remix.run Logo
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.

the_af 7 minutes ago | parent [-]

> If you’re not familiar, browsing the site may be worth your while

Not inclined to do this though, his site doesn't exactly seem easy to browse either. Maybe a reflection of his bizarre takes?

Do you have some examples of well-informed articles by him? I found one about "syntax vs semantics" that seems as inflammatory and ill-informed as TFA under discussion here. I'm not inclined to give this person much leniency...

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).

jey 9 hours ago | parent | next [-]

ReScript is better described as a descendant (and fork) of ReasonML aimed to fit into the JS ecosystem. In contrast to js_of_ocaml, ReScript prioritizes interoperability with existing JS code and APIs over interop with existing OCaml code, whereas js_of_ocaml takes the opposite approach. So people looking for an improved version of JavaScript or TypeScript should probably choose ReScript, but people who are porting an existing OCaml program might prefer js_of_ocaml.

davesnx 2 hours ago | parent [-]

There are a few missleadings in your message:

ReScript isnt a fork of Reason, jsoo focuses only on compiling all OCaml and allows JS interop

Reason with Melange is a viable option for JS/TS devs.

RandomThoughts3 2 hours ago | parent | prev | next [-]

It's not more reasonable. It explicitely designed to look like JS which is, well, bad. Some of the choices are extremely annoying and overall useless like reintroducing parentheses for function arguments.

There is a reason - pun intended - it didn't take off at all with the community.

JoelJacobson 8 hours ago | parent | prev | next [-]

I love the idea of Reason/ReScript. I hope they can figure out a way to work together and join forces somehow, the contributions to both repos seems to have faded over the last years, but maybe that's because the projects have stabilized, I don't know.

I've had lots of fun playing with Reason a few years ago. I created an interactive real-time visualization tool, to see a Regexp transform into a NFA to DFA to minimal DFA graph: http://compiler.org/reason-re-nfa/src/index.html It only works for basic regexes though.

chrischen 6 hours ago | parent | next [-]

The ReasonML workflow continued on as Melange.

https://melange.re

danielstocks 8 hours ago | parent | prev [-]

I can’t speak for Reason but the ReScript project and community is very alive and vibrant. There’s been some major improvements over the past year and overall it’s much more appealing and mature now compared with only a few years ago. We’ve been using it in a fairly large React app for a while and the experience has been very good.

BrawnyBadger53 9 hours ago | parent | prev [-]

I feel like ReasonML should have the capacity to help bridge the gap for people learning ocaml if it weren't so hidden.

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.

bvrmn 5 hours ago | parent [-]

TBF he has such notion:

> because a 0 arity function without side-effect is just constant.

pyrale 20 minutes ago | parent [-]

n-arity functions are also constants. 0 is not a special case there. Their behaviour won't change depending on the context from which you call them. A large part of FP is that functions _are_ values.

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.

pyrale 16 minutes ago | parent [-]

Keyboards are also extremely error-prone. I can't count the times where I mistyped because of that. After each keystroke, people should type a "confirm" character in order to make sure of what they're doing.

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).