Concurrency in Ocaml: It seems like the CML style never took off for anybody?

[Full disclosure: I’m pretty much a threads/mutex/condvar hacker myself, having spent too many years putting out Java server dumpster-fires to really be able to switch to one of these other styles the Kids These Days come up with (j/k j/k: I used CML for a SUNRPC project in SML in 1990; I realize it’s not hot off the griddle)]

I’m curious about whether anybody in the Ocaml community uses the CML style of concurrency? Ocaml has had basic support for CML since forever (“Event”) but I’ve never seen anybody use it. There are probably lots of technical reasons for that, but first, I’m curious if anybody out there actually likes this model of concurrency for ML programming. After all, it’s pretty successful in Erlang, and (heh) Golang seems to be giving it the ol’ college try, too.

No need to respond unless you’re really into CML/CSP/etc. I mean, my default assumption is, nobody does it, b/c threads/promises/etc are where the main body of programmers is. I’m certainly there.

Thanks in advance!

1 Like

That’s interesting, I didn’t actually know that OCaml supported CML style. I just found this sample code that demonstrates it: http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora177.html

Do you have pointers to any more example code for OCaml using events and channels? I’d like to get a feel for how you could do the usual async operations.

Ha! I’m in the same position as you are! OK, well, maybe (theoretically) epsilon better:

30 years ago I hacked with CML on the then-extant SML/NJ. And that’s it. In-between I had a commercial career, and … y’know the brain only has so much L3 cache space. I spooled that memory off to tape, which got lost in some warehouse a long time ago. So I’m basically looking for people who actually think this CML stuff is the way to go, and wanna talk about it.

Now, I should note that there is a very successful language community where this stuff is … “table stakes”. I’m talking about the Erlang community. The fact that they have nontrivial systems built using this structuring methodology/formalism, tells us that it isn’t bunk. So please don’t take this as me saying “gosh, is CML bunk?” It isn’t: Erlang is proof of that.

So: if you want to understand this model of computation, I guess the place to start is with Erlang. Me, I’m just trying to understand what the state-of-the-art in ML, regarding CML. If the answer is “look elsewhere”, that’s a perfectly fine answer, b/c I personally think in terms of thread/mutex/condvar. I know it’s wrong, but I can’t help it.

Ha!

P.S. Why is it wrong? There’s that famous paper “message-passing is superior to shared-memory” out of MSR, so many years ago, right? It pretty much settled the question, didn’t it?

1 Like

I like Event. I used to teach its usage. And at that time, I used to write things that use it. Nowadays, not really.

I think there’s beauty in Event, but there’s also poor performance if you use it too intensively, which may happen easily when you’re carried away by the elegance of the thing instead of focusing on the practical objectives!

I’ve built a couple of concurrent apps in Elixir, so using OTP and the BEAM, close enough to Erlang, and to be honest the OCaml channels and events feel somewhat different :slight_smile: Mainly I see differences in process supervision, encapsulated non blocking I/O, and the full-fledged concurrency-oriented standard library (OTP).

OCaml Event seems much more primitive in comparison, but I’ll keep an eye out for more interesting examples.

1 Like

Very fair. Very, very fair. erlang’s well-developed semantics certainly leaves anything in the ML world … in the dust. I don’t know if even CML had process-supervision (kinda doubt it did).

1 Like

Almost random question: did anybody try to compile(or transpile) OCaml to BEAM(Erlang/Elixir)?

2 Likes

Some ML-like languages exist for the BEAM VM, like Alpaca and Gleam. Some people made Ocaml programs run on the BEAM VM apparently.

Other than that, i am not aware of an elixir/erlang_of_ocaml compiler.

I’m toying with that idea.

But right now the only non-toy ML’ish language for Erlang/beam is…surprise…PureScript — https://github.com/purerl/purescript