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

nine_k 7 months ago | parent | 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 7 months 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 7 months 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.

obeavs 7 months ago | parent | prev | next [-]

Worth nothing that the former lead dev of ReScript left to create a WASM-first language call Moonbit (https://www.moonbitlang.com/). The language design is awesome and corrects a lot of the corners that they just couldn't get around in OCAML. A touch early, but really well done.

tharmas 7 months ago | parent | next [-]

Thanks, I didnt know about Moonbitlang.

yawaramin 7 months ago | parent | prev [-]

Worth noting*

Not nothing ;-)

JoelJacobson 7 months 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.

danielstocks 7 months ago | parent | next [-]

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.

chrischen 7 months ago | parent | prev [-]

The ReasonML workflow continued on as Melange.

https://melange.re

BrawnyBadger53 7 months ago | parent | prev | next [-]

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

Taikonerd 7 months ago | parent [-]

I wish they would update their blog![0] The last post is from Aug. 2018, which definitely gives the impression that the project is dead.

But it's not dead, if you look at their GitHub.[1]

[0] https://reasonml.github.io/blog/

[1] https://github.com/reasonml/reason

davesnx 7 months ago | parent [-]

Shame on me; I have a few draft posts that never got the chance to publish. My non-native english doesn't fully help ^^

Expect some of them to be published at the end of the year or early january!

Taikonerd 7 months ago | parent [-]

Glad to hear it!

RandomThoughts3 7 months ago | parent | prev [-]

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.

nsonha 7 months ago | parent [-]

I recommend Fabble and F#, a language that went the correct course of programming evolution, from braces to indent, instead of the other way around :)

p4bl0 7 months 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.

soraminazuki 7 months 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 months 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 7 months ago | parent [-]

TBF he has such notion:

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

pyrale 7 months 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.

sevensor 7 months ago | parent | prev | 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 months 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...

sevensor 7 months ago | parent | next [-]

I think the emacs rants are fairly well known. Here’s an example: http://xahlee.info/emacs/emacs/emacs_manual_problem_example....

FeloniousHam 7 months ago | parent | prev [-]

He has Mac keybindings for the most rational home row key navigation scheme: http://xahlee.info/kbd/osx_keybinding.html

RandomThoughts3 7 months 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.

remexre 7 months 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 7 months ago | parent | prev | next [-]

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

yawaramin 7 months ago | parent [-]

> ...(C, bourne shell, etc etc) have this exact same problem...

Doesn't Bourne shell syntax have terminator keywords for all control flow structures? https://unix.stackexchange.com/a/256152

seanhunter 7 months ago | parent [-]

It does (so you have esac to end a case statement in this case) but depending on what combination of line noise (;& vs ;;) you use, you have case fallthrough like c. You have to sort of want to do it (ie ;& isn't very common) but it does happen.

Case fallthrough almost always ends in tears.

yodsanklai 7 months ago | parent | prev [-]

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