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

Besides GC and the lightweight syntax (relative to Rust), what is it about OCaml that makes it so wonderful for implementing complicated algorithms?


Well, the big one is GC.

Here are a few others:

- both polymorphic variants and GADTs are extremely powerful mechanisms to let you keep track of invariants, in a manner that cannot be replicated readably in Rust so far;

- OCaml's pattern-matching is a bit more flexible than Rust's ;

- (thanks to the GC) OCaml's closures are much more flexible than Rust closures;

- I guess OCaml's blindingly fast exceptions can be useful for some algorithms, although I haven't really experienced the need for them myself.

Again, that's not to say that Rust doesn't have great stuff for it (affine types 4eva!) or that OCaml doesn't have its own limitations – Rust is currently my main language and I do not regret it.

But there are some algorithms that I really don't want to write in Rust. Recently, for instance, I stumbled upon this: http://weblog.jamisbuck.org/2010/12/29/maze-generation-eller... . Trivial algorithm, trivial to write in OCaml, feasible but much less straightforward in Rust.


Exactly that, lock-free algorithms are specially hard to get a correct implementation without tracing GC support.


Why?


Here is an overview, read also the comments.

https://concurrencyfreaks.blogspot.com/2017/08/why-is-memory...




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

Search: