Hacker News new | past | comments | ask | show | jobs | submit login

What are some of the factors that contribute to OCaml being your language of choice / do you feel limited by the poor multicore parallelism story?



Here are the factors that made OCaml my language of choice, after thousands of hours spent learning and using other languages.

Strong typing with type inference makes it quick and easy to write code (no verbose declarations) that is safe to execute, meaning that the compiler catches 99% of bugs that you usually make, which other languages let through.

Algebraic data types and also a more flexible (if a bit more dangerous) kind of typing that is still type-safe and compiler-checked, but dynamic, called polymorphic variants. These features make it a breeze to define a solid foundation of types for you to write your algorithms on.

Pure functional programming (no mutation) as the default way to write code, with a lightweight and readable syntax. This is a plus because it's the most bug-free way to write code.

Classical imperative programming (loops, I/O, variable mutation) when you need it or when you find it useful for a given task (simplest example: inserting debug prints halfway through a function) without resorting to mind-bending constructs that hide what's really going on behind a facade of purity (Monads and the horrid monad stacks of Haskell, I'm looking at you.)

Compiles to machine code so no useless speed limit (as found in interpreted languages) or heavy startup time and memory footprint (as in JIT / Java)

Predictable complexity (CPU) and memory usage. This is true for most languages, except for Haskell.

Sane exception support. This is also true for most languages, except for Go.

IMHO the poor multicore parallelism issue is way overblown. Yes, most CPUs nowadays have many cores. But if you are writing server/backend code, being limited to a single-threaded model is usually not a problem, because your server will be handling tens or hundreds of simultaneous requests anyway, and handling one at a time on a single core is better for overall throughput. OTOH, if you are writing heavy numerical single-application code, you are better off handling the parallelism by hand, that is, choosing what gets palallelized and how, which library to use, and so on. We don't have hundred-core CPUs yet, so it's a bit early to worry about it. Besides, they are working on it.

PS: I recommend the book https://realworldocaml.org/ (and the Core standard library) for anybody starting with the language.


Not OP but also OCaml user here, I consider Haskell's laziness to be the wrong default and think it makes it harder to reason about programs, and I prefer the 'mostly pure' approach of ML languages to strict purity.

For me OCaml or the ML family hit the sweet spot of language design.

I will agree that the parallelism issue can be a problem.


Please tell me about the parallelism problem? I love that Haskell can auto-parallelize and is very safe. But, I'm ready to kick it to the curb over stupid lazyiness-induced memory explosions. But I'd be sad to go back to having to worry about threads and safety.

I'd love to give OCaml a go. Tell me why I'll end up disgruntled.


There is no parallelism, the runtime doesn't offer any. The best you can do is fork(). But there is an effort ongoing for a few years now, multicore-ocaml, which will be available mainstream when it's Ready(no ETA).


Then you should try Idriss. This language is haskell with dependent typing and static by default.


Multicore is always just around the corner!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: