3 ms·
This is such a weird complaint that it feels like engagement bait. "Let x be equal to 4 in x * x" is a natural way to express a concept in English. The equiva
by ubertaco 2y ago
This is such a weird complaint that it feels like engagement bait.
"Let x be equal to 4 in x * x" is a natural way to express a concept in English.
The equivalent OCaml code is:
let x = 4 in
x * x
I'm not sure how that qualifies as "sucks"?
In fact, the `in` makes OCaml's scoping rules some of the easiest to follow. This is valid OCaml code:
let x = 4 in
let y = 3 in
let z = 2 in
x * y * z
let x = 5 in
let y = 6 in
let z = 7 in
x * y * z
The phrasing of "let x = 4 in <this expression>" makes it explicit where x is defined as 4, vs where it's instead (in a different expression) defined as 5.
I have an easier time understanding scope in OCaml, which explicitly spells out its scoping rules in plain-English syntax, than I do in Rust or JavaScript, which use the deceptively-simple-looking braces but also wild concepts like lifetimes or hoisting.
- yawaramin 2y agoAnd for people who don't like writing so many 'in's, we also have 'and': let x = 1 and y = 2 and z = 3 in x * y * z Which indicates that the binding of y can't refer to x and so on.
- steinuil 2y agoI've written a lot of OCaml and I always thought `let .. and .. in` indicated that the definitions were mutually recursive and that you could refer to y in x, like in `let rec .. and` or `type .. and`! That's surprising.
- yawaramin 2y agoI never thought about it much before but after seeing let+ and and+ 'debut' as operators for applicative functors (ie parallel application) it sort of clicked for me then.