Live data from Hacker News

OCaml Syntax Sucks (2016)

xahlee.info

41–50 of 140 posts

Re: OCaml Syntax Sucks (2016)

#41
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…

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

Re: OCaml Syntax Sucks (2016)

#43
Weak arguments in the article with badly chosen examples.

If one wanted to criticize OCaml syntax, the need for .mli-files (with different syntax for function signatures) and the rather clunky module/signature syntax would be better candidates.

Re: OCaml Syntax Sucks (2016)

#44
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 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…

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.

Re: OCaml Syntax Sucks (2016)

#45

The more I used ocaml the more I found beauty in the syntax. It’s very ergonomic in many ways: 1. It’s whitespace insensitive, which means I can code something up really messy and the code formatted will automatically fix it up for me. 2. In general there aren’t a ton of punctuation characters that are very common, which is great for typing ergonomics. Don’t get me wrong, there are still a lot of symbols, but I feel…

2. In general there aren’t a ton of punctuation characters that are very common, which is great for typing ergonomics. Don’t get me wrong, there are still a lot of symbols, but I feel compared to some languages such as Rust, they’re used a lot less. I never really seen someone put that into words. I always feel a certain kind of weird when I look at a language with tons of punctuation (Typescript is good example).

The lambda syntax and default lambda parameters alone make typescript very hard to parse

Re: OCaml Syntax Sucks (2016)

#46
post #14

Worked on an ocaml codebase for two years. My advice is: choose a different language. It's just not a great dev experience in general

Depends on what you compare it with, I guess. (I worked in OCaml and Haskell and other 'weird' languages professionally in different jobs for many years.)

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

Re: OCaml Syntax Sucks (2016)

#47
post #33
post #7

Earlier quoted context omitted.

> It is bespoke and async-specific. There is nothing wrong with it but it's necessary to acknowledge this limitation. I would disagree. If you need to have a bespoke set of syntax, then something is not integrated where it should be. The language design should not be such that you are writing things differently, depending on the paradigm that you're handling. That's not something that occurs in every language, so it…

F#'s computation expressions are closely related to Haskell's monads + do-notation combo, CEs are both more limited than Haskell's approach to monads (from a type expressibility perspective) and more expressive than pure monads (from a modeling perspective, can model a general class of computational structures beyond monads; CE's also share F#'s syntax, with extensible semantics). This notation can be advantageous an…

However, most of the industry has moved away from DSLs. Whilst having a unique language can make certain things more expressive, having something standard makes mistakes happen less, and increases the effectiveness of a programmer. Lisp doesn't rule our day to day.

We shoehorn things that feel like, but are structurally different, to DSLs into config files and the like, using JSON/YAML/etc in rough ways, because DSLs introduce a cognitive overhead that doesn't need to be there.

That the shoehorn happens, does mean that DSLs are something natural to reach for. You're right there. But that we have moved away, as an industry, indicates that using any kind of DSL is a smell. That there probably is a better way to do it.

Having a core language feature using a DSL, is a smell. It could be done better.

Re: OCaml Syntax Sucks (2016)

#48

Weak arguments in the article with badly chosen examples. If one wanted to criticize OCaml syntax, the need for .mli-files (with different syntax for function signatures) and the rather clunky module/signature syntax would be better candidates.

I actually rather like the mli-files. It's a nice file to read, with the documentation and externally available symbols only. However, the fact that the syntax is so different is a bit annoying.

Sometimes I wrote (haven't written OCaml for some time now..) functions like:

    let foo: int -> int = fun x ->
      ..
just to make them more similar to the syntax

    val foo: int -> int
in the module types.

Re: OCaml Syntax Sucks (2016)

#49
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…

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

Re: OCaml Syntax Sucks (2016)

#50

I find it less abutting now that I know about let expressions in lambda calculus. it's still verbose though. do notation please.

There is a kind of "do notation" in OCaml with binding operators [1] (let*) for monads and (let+) for applicatives that is actually quite pleasant in practice.

[1] https://ocaml.org/manual/5.2/bindingops.html

Post reply on HN