Live data from Hacker News

OCaml Syntax Sucks (2016)

xahlee.info

101–110 of 140 posts

Re: OCaml Syntax Sucks (2016)

#101
post #12

Earlier quoted context omitted.

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

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

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

Re: OCaml Syntax Sucks (2016)

#103
post #46

Earlier quoted context omitted.

Fsharp is pretty good in teams f tooling at least when compared to other functional languages

Although I'm not a Microsoft fan, their docs for F# are worlds ahead of anything I've seen for OCaml (I know a few OCaml folks are working to fix this). I've considered trying it for Advent of Code this year.

It's definitely worth it to try

Re: OCaml Syntax Sucks (2016)

#104
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 " 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.

Re: OCaml Syntax Sucks (2016)

#105
post #96

Earlier quoted context omitted.

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

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

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

Re: OCaml Syntax Sucks (2016)

#106

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 l…

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

Re: OCaml Syntax Sucks (2016)

#107

Another thing I personally hate about OCaml's syntax is the order of generic parameters being backwards. I know why it's like that, but it still doesn't make any sense to me both as a programmer and as a non-native english speaker.

It's definitely quirky in its inconsistency, but

   type 'a Tree = 
     | Node of ('a Tree, 'a Tree)
     | Leaf of 'a
Is saying "The possible cases for the type describing an 'a Tree are: a Node of two other 'a subtrees, or else a Leaf of an 'a."

Then when you concrete-ize it, you have an "int Tree" or a "string Tree".

This is a little clearer with thinking of the List datatype: this is a number list, that's a string list, that's a grocery list, this is a guest list...etc.

One nice thing in F# is that there's an ability to "standardize" how you write generics to look more like the (admittedly arbitrary) way that C# or Java or C++ write them:

    type Tree =
      | Node of (Tree, Tree)
      | Leaf of 'a

Re: OCaml Syntax Sucks (2016)

#108
post #97
post #12

Earlier quoted context omitted.

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

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.

Worth noting*

Not nothing ;-)

Re: OCaml Syntax Sucks (2016)

#109
post #9

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 format…

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…

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

Re: OCaml Syntax Sucks (2016)

#110

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 l…

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

I'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.
Post reply on HN