Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Other than satisfying curiosity, why should I learn OCaml?


Programs written in ML dialects tend to have the astounding property that once they compile, they are correct. And this is only a slight exaggeration.

This property alone is worthwhile to learn one, if for nothing else then to be able to apply the same succesfull patterns in other languages.

I didn't know how to write proper strongly typed code until I learnt Ocaml - I had several years of experience in C++ and knew Java, but, they really don't go out of their way to expose the patterns that allow write the best code possible. With the lens of Ocaml under my belt I could better discern the shiny patterns that were buried all that ugly dirt of multiple inheritance and such bollocks.

Which ML language should you learn? Any of them is good as the next if it's for education - a modern tooling, support and community is a nice bonus.

ML languages in production nowadays include Ocaml, F# and, to some extent given it has so much isomorphism with its kin, Scala. Scala can be considered an ML dialect, although with the weirdest syntax of them all.

Unless you are quite certain Ocaml is the exact language you want to learn, F# is a good alternative.


I'd say Elm is a plausible alternative, though maybe not right now: there are a lot of small rough edges in the ecosystem after 0.19 release. On the other hand, a lot of the 0.x breakage comes from the very high priority of the unusual long-term plan, which I'd formulate as something like following: distill that essential property of ML while shaving all the bells and whistles that just happen to be in other dialects.


Are there any plans to bring Elm to any non-javascript runtime?


Long term: yes, the controversial banning of "native" code [1] is in part motivated by the idea that JS should be an interchangeable implementation detail.

Short term, officially: hell no, Evan declares a sharp focus on one use-case and discourages experiments with other platforms, even server-side node.js [2].

Short term, unofficially: I heard of a compiler to Elixir [3]. Elm's stance on "native code" (see above) seems to make such projects feasible.

[1] https://discourse.elm-lang.org/t/native-code-in-0-19/826

[2] https://github.com/elm/projects/blob/master/roadmap.md#can-i...

[3] https://github.com/wende/elchemy


Ocaml has an amazing type systems that’s been designed well from the ground up. There’s excellent pattern matching, no null/nil, immutability of values, higher-order functions, etc. The type systems of a lot of new languages have gotten their inspiration from OCaml. For example, the Flow type checker for JavaScript is heavily Ocaml-inspired and itself written in Ocaml.

On practical grounds, there’s ReasonML: https://reasonml.github.io

ReasonML, a dialect of Ocaml is great for web development. Especially if you use React, due to: https://reasonml.github.io/reason-react/

ReasonML & ReasonReact are both officially supported & developed by Facebook. The creator of React is also strongly behind ReasonML.

Alternatively, there’s also BuckleScript (whose compiler is shared with ReasonML), which lets you use Ocaml with its standard syntax on the web.

BuckleScript is officially supported & developed by Bloomberg.


[flagged]


Could you please tell us how rust is better at functional programming than OCaml?

Your comment appears unsubstantiated to me. I am not sure how you reached the conclusion of equating learning OCaml with learning BASIC, but I would be happy to know your reasoning.


It would be like learning BASIC.

If I had an opportunity to do Real Work in BBC BASIC I would jump on it




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: