from Hacker News

OCaml 5.0 Multicore is out

by sadiq on 12/16/22, 12:21 PM with 173 comments

  • by logicchains on 12/16/22, 3:41 PM

    I remember around a decade ago when I first got into programming, I was super excited that OCaml would soon get multicore, regularly checking the progress. Although it took a lot longer than I imagined it would, nevertheless it feels amazing to see it finally here, almost like a dream when you've waited so long for something and you can't believe it's finally happening.
  • by nequo on 12/16/22, 3:54 PM

    Signals and Threads had an interview with Anil Madhavapeddy last year:

    https://signalsandthreads.com/what-is-an-operating-system/

    He talked about the work to put a multicore-ready memory model[1] and GC[2] under OCaml.

    [1] https://anil.recoil.org/papers/2018-pldi-memorymodel.pdf

    [2] https://arxiv.org/abs/2004.11663

  • by mbac32768 on 12/16/22, 4:20 PM

    People who aren't PL theorists understand the multicore benefits even if the retrofitting paper might be over their heads. On the other hand, the bounding data races in time and space paper/presentation is also a fairly significant change that I don't think the average dev has an easy to understand relationship with.

    Anil covers it in a bit more plain English in this Signals and Threads episode. Here's a bit of the transcript, starting at about 50 minutes in: https://signalsandthreads.com/what-is-an-operating-system/

    > Ron: Do you have a pithy example of a pitfall in multicore Java that doesn’t exist in multicore OCaml?

    > Anil: There’s something called a data race. And when you have a data race, this means that two threads of parallel execution are accessing the same memory at the same time. At this point, the program has to decide what the semantics are. In C++, for example, when you have a data race, it results in undefined behavior for the rest of the program, the program can do anything. Conventionally, daemons could fly out of your nose is an example of just what the compiler can do.

    > In Java, you can have data races that are bounded in time so the fact that you change a value can mean later on in execution, because of the workings of the JVM, you can then have some kind of undefined behavior. It’s very hard to debug because it is happening temporally across executions of multiple threads.

    > In OCaml, we guarantee that the program is consistent and sequentially consistent between data races. It’s hard to explain any more without showing you fragments of code. But conceptually, if there’s a data race in OCaml code, it will not spread in either space or time. In C++, if there’s a data race, it’ll spread to the rest of the codebase. In Java, if there’s a data race, it’ll spread through potentially multiple executions of that bit of code in the future.

    > In OCaml, none of those things happen. The data race happens, some consequence exists in that particular part of the code but it doesn’t spread through the program. So if you’re debugging it, you can spot your data race because it happens in a very constrained part of the application and that modularity is obviously essential for any kind of semantic reasoning about the program because you can’t be looking in your logging library for undefined behavior when you’re working on a trading strategy or something else. It’s got to be in your face, at the point.

    (and so on)

  • by ecshafer on 12/16/22, 7:34 PM

    OCaml is one of those languages that is a real joy to use and makes me wonder why its not used more often. I feel like if I jump into a Lisp or ML language, I am so productive and can write some really complicated software with relative ease. But they are relatively rare in industry, and I have never really crossed the t on why, despite various reasonings about it.

    This is a great achievement for OCaml, but does anyone have an explanation on why it was so difficult to implement for them?

  • by jon_smark on 12/16/22, 12:35 PM

    Congratulations and a big thank you to the OCaml team! I hope that multicore support finally ticks all the requirement boxes that had prevented many from taking a serious look at OCaml. The language certainly deserves it: it hits that sweet spot between expressiveness, performance, and pragmatism like no other.
  • by eatonphil on 12/16/22, 8:20 PM

    If you want to see an example of it: https://v2.ocaml.org/releases/5.0/manual/parallelism.html.
  • by rg111 on 12/16/22, 7:43 PM

    What is the most fun and best source to learn OCaml for a programmer?

    I know this one [0] so far. Also the famous Coursera PL course [1] covers ML.

    [0]: https://cs3110.github.io/textbook/cover.html

    [1]: https://coursera.org/learn/programming-languages

  • by sadiq on 12/16/22, 12:23 PM

    There are a few OCaml contributors lurking and happy to answer questions if you have them.
  • by UncleOxidant on 12/16/22, 5:28 PM

        $ opam update
        $ opam switch create 5.0.0 --repositories=default
        $ eval $(opam env)
        $ ocaml
        OCaml version 5.0.0
        Enter #help;; for help.
  • by runevault on 12/16/22, 4:33 PM

    Been dabbling in f# lately, but this has me wanting to give OCaml a try for comparison, very interested in the new effects stuff.
  • by systems on 12/16/22, 5:57 PM

    Still no native windows build To install on windows, I guess your best bet is via WSL (Windows Subsystem for Linux)

    I now run mainly on windows and this is an issue for me to try OCaml

  • by no_wizard on 12/16/22, 3:57 PM

    Jane Street must be so happy today! I think this opens up a whole new host of fast applications on ocaml.

    I wonder how this will affect ReScript

  • by melling on 12/16/22, 1:08 PM

    OCaml has a reputation for being fast.

    https://sixthhappiness.github.io/articles/python-scheme-and-...

    Does anyone have any multicore benchmarks that illustrate performance increases in 5.0?

  • by vkazanov on 12/16/22, 12:56 PM

    Amazing! An incredible amount of effort! This was holding back ocaml almost for as long as I remember - and now it's just gone.

    Congratulations to the team!

    What are the next plans for the project? Spread newly available features..?

  • by maattdd on 12/16/22, 1:03 PM

    Amazing work from the team! I wonder if this is actually the first mainstream language which has managed to remove its "global lock" without breaking changes ?
  • by mnming on 12/16/22, 10:38 PM

    Is it still possible to use Reason as frontend for Ocaml 5?

    I felt an ergonomic and modern syntax is the only missing piece in Ocaml.

  • by pjmlp on 12/16/22, 2:55 PM

    Great news! Kudos to everyone that helped make this happen.
  • by badrabbit on 12/16/22, 12:56 PM

    I started learning ocaml and i stopped when I heard about the lack of multicore support (felt like it wasn't ready for general purpose use) this is an awesome developemt. From all the functional lanuages I've sampled so far Ocaml is the most intuitive. Hoping to finally get into it in 2023.

    Great work Ocaml devs!

  • by iainctduncan on 12/19/22, 4:46 PM

    My interest is in (soft) real-time music systems. I'm curious if anyone can comment whether this will make OCaml a potential language in that domain. I've held off on Haskell because of the whole "you might not know how long this will take", which is a non-starter for music. I mostly use Scheme and C (and Max/MSP but with custom C/Scheme in it), but I'd love to use something other than C for the low level stuff.

    Wondering if anyone can comment on whether this might mean OCaml can be a contender in that space now?

  • by rg111 on 12/16/22, 7:41 PM

    What is the most fun and best source to learn OCaml for a programmer?

    I know this one [0] so far. Also the famous Coursera PL course covers ML.

    [0]: https://cs3110.github.io/textbook/cover.html

  • by nih0 on 12/16/22, 3:29 PM

    this was being talked about when i was still in high school and last year i did my masters
  • by lilactown on 12/16/22, 4:55 PM

    Is there a guide on how to use the new constructs? The link to the 5.0 docs was broken on the site, and after manually fixing the URL all I found was some type annotations in the `Effects` module.
  • by aylmao on 12/16/22, 3:15 PM

    No way, it's finally out! This is fantastic news.
  • by ghostwriter on 12/16/22, 5:00 PM

    Multicore is there, STM instead of mutable imperative logic in all the libraries developed for the past two decades: not so much though.
  • by Decabytes on 12/16/22, 4:46 PM

    I'm curious about what design decisions lead to OCaml not having Multi-threading when version 1.0 came out. Majorly impressive work getting something as complex as that added on afterwards. Kudos to everyone involved!
  • by InitEnabler on 12/16/22, 4:35 PM

    What OSS is out there that uses OCaml?
  • by leoh on 12/17/22, 1:17 AM

    Anyone know if OCaml was used at FTX, btw? Given that it's big at Jane Street, where SBF worked.
  • by didip on 12/16/22, 11:39 PM

    OCaml syntax is a little hard to read for plebian like me.

    What is the use cases for OCaml?

  • by melony on 12/17/22, 6:47 AM

    What's the current status of Esy? https://github.com/esy/esy

    Any plans to backport its design back to Opam?

  • by toolslive on 12/16/22, 3:36 PM

    Halleluja! I think they were at it for more than a decade.
  • by Alifatisk on 12/16/22, 4:15 PM

    What an amazing ending of 2022!

    Just Hotwire Strada left.

  • by keepquestioning on 12/16/22, 6:41 PM

    Does it support Apple Silicon Macs?
  • by laylomo2 on 12/16/22, 10:15 PM

    Congrats! Super excited to start playing around with the effects system.
  • by acaloiar on 12/16/22, 11:25 PM

    Meta: I believe the title should be "OCaml 5 is out!", as it appears on the OCaml site.

    At first glance, I understood the title "OCaml 5.0 Multicore is out" to mean "Multicore is no longer part of OCaml 5.0".

  • by pjmlp on 12/16/22, 2:55 PM

    Great news! Kudos to everyone that helped make this happen.
  • by 2wrist on 12/16/22, 2:36 PM

    Oh congratulations! Well done to all involved!
  • by poulpy123 on 12/16/22, 7:26 PM

    any easy way to try it on windows (not wsl) ?