OCaml's Wings for Machine Learning

61 musha68k 31 4/30/2025, 12:31:47 PM github.com ↗

Comments (31)

toolslive · 1h ago
Am I the only one who doesn't like notebooks ?

I don't want to write code in a browser. For python you have something like ipython which allows you to have an interactive experience, while also allowing you to have your favourite editing environment. For ocaml, surely there are also repls that provide this kind of thing.

nathan_compton · 16m ago
I hate em. They make people write bad code and using them for interactive development is much worse than using a REPL. I cannot understand what people see in them.
pletnes · 11m ago
I use my IDE when I care about the production code, but I prefer notebooks when I’m just using code to understand data through visualization and statistics.

It drives me nuts that some people see this as «either or».

Linqpad is another and different take on data-driven environments. As is various «SQL admin» alternatives.

patagurbon · 7m ago
They’re great for teaching. But I agree for actual work.
bb1234 · 52m ago
I don't like them either. I find it hard to articulate why I don't like them. I definitely have experienced problems with them where they get into some state where the cell results are incorrect. Then, if I restart the kernel and run the cells again, I get the correct result. But I don't like them for reasons other than this one, and cannot explain why. I prefer the ipython REPL to the notebook.
neonsunset · 1h ago
Me too, I just write .fsx scripts instead (F# interactive), it works nicely together with Plotly.NET. And can crunch / parallelize well if you want to do something over many files.
behnamoh · 2h ago
OCaml surprises me—it's old enough to be mature in terms of features and libs, and it's got a small but enthusiastic community, but every time I tried to convince myself to OCaml I found myself more drawn to Haskell and Elixir.
giraffe_lady · 2h ago
I like ocaml for the things other people like go for. It's a grimy roughneck language. Not a lot of fun to play around with or explore ideas but in my experience codebases written in it are stable and age well, easy to maintain.

Elixir vs ocaml I use both languages but for such completely different things I don't even think about a comparison. Elixir is for when the problem I have suits beam's strengths.

noelwelsh · 1h ago
Its unfortunate the cleaned up syntax never took off, and that OCaml dropped the ball on multicore for over a decade. If OCaml had decent multicore around 2010 or so the current programming language langscape could look very different.
StopDisinfo910 · 1h ago
Python had no multicore during the same period and that never prevented it from becoming successful. Plus, Ocaml always had descent solution for concurrent I/O. The absence of multicore is a complete red herring in why Ocaml isn't more successful.

Ocaml issue never was the syntax which is completely fine. The current syntax is actually a lot nicer that what Facebook proposed. Ocaml issue is not being a USA-born project nor having a significant marketing push in English.

Plus, Ocaml always was too far ahead of its time (including now with its effect system). First, you have the functional approach which was already very unfamiliar for most. Then, you have to add module level programming on top which is still very unfamiliar to most. Just look at this comment page and people thinking Ocaml is not fun to use or less interesting than Haskell, it's trully sad.

Multicore has added the extremely promising effect system but that's once again a step too far for most current developers.

In a lof of way, Ocaml is to programming language what the Pixies are to rock music. Everyone who felt deeply in love with it went on to write a language of their own. Some got really successful.

noelwelsh · 2m ago
Go / Rust / Scala are the competition for OCaml, not Python. Around 2010 there weren't great options if you wanted a vaguely modern language in the server backend space. Java was stagnant and Scala was just getting going commercially. OCaml could have been in there.
kangda123 · 1h ago
As far as my experience, there's little code in Python that I would like to replace with OCaml. Python stuff is research code and small services that were written hastily.

I would love to replace my Go code with OCaml. It was always kind of on the verge though. On one hand, once you use a proper type system, you cannot look at Go. On the other, Go's multicore is just so much better than Async/Lwt. In terms of programming, in terms of debuggability, surely in terms of performance too. Having proper multithreading in 5.0 suddenly makes OCaml strictly superior in my (rather biased) opinion.

hardwaregeek · 44m ago
I'd disagree about syntax. It really does matter. So much of Rust's success is tricking people into writing a functional style while having it look like an imperative language. OCaml syntax isn't bad per se but it's unfamiliar and that's enough to discourage users.
deredede · 59m ago
The lack of ad-hoc polymorphism has to be there somewhere as well.
giraffe_lady · 51m ago
I don't think so really. It might help lure people over from haskell or rust or whatever but ocaml has its own solutions to the problems solved by ad hoc polymorphism. Usually in the module system, sometimes a ppx.

There's nothing comparable to ocaml's module system that I know of in any other mature language so no one really arrives in ocaml with well developed intuition for what sorts of things are possible and worth doing with it. But once you've put the time in it's usually the correct answer to "how to do I do <haskell type system thing> in ocaml."

I'm not a type systems expert though and it's likely there are some novel & unique situations where it's the best or only solution. Just maybe not as much as people assume from outside. Anyway I think there is a proposal for it so it'll probably work its way in eventually.

behnamoh · 1h ago
> Ocaml issue is not being a USA-born project nor having a significant marketing push in English.

Python is a counter argument here.

StopDisinfo910 · 1h ago
It's not. Van Rossum is Dutch but Python always had a strong marketing push in English.

The first version was announced in English on Usenet. Van Rossum moved to the USA quite quickly to work on Python from CNRI in 1995. Then, it got funding from DARPA in 1999 with this as part of its pitch: "Create a code that is easy to understand and looks as easy as the English language."

Ocaml meanwhile is an INRIA child made by a French team to develop another INRIA child made by another French team. I think in Europe, that's approximately as US hostile as you can be.

Actually, Ocaml has only become somewhat popular since it's pushed a bit from the UK which I find amusing.

behnamoh · 1h ago
> Its unfortunate the cleaned up syntax never took off, and that OCaml dropped the ball on multicore for over a decade.

It just shows the mindset of its devs was a little behind the realities of the industry, or they simply didn't care about concurrency.

In comparison, I like how Python always tries to be on top of things by exploring new PEPs.

sidkshatriya · 1h ago
> It just shows the mindset of its devs was a little behind the realities of the industry, or they simply didn't care about concurrency.

OCaml cared about concurrency (e.g. Lwt, Async are old libraries that provide concurrency -- they didn't need multicore Ocaml). OCaml didn't care so much about true _parallelism_ in threads until recently. Parallelism was to be obtained via processes and not threads in pre OCaml 5.0. True parallelism in threads is available in OCaml >= 5.0

Python is actually trying to go multicore too ! OCaml however beat it to the punch. The strengths of Python are elsewhere though, a topic for another day.

ackfoobar · 1h ago
To be pedantic, concurrency in OCaml has been fine with lwt. Single threaded concurrency, not unlike how JS does it.
toolslive · 1h ago
I'm going to be sarcastic _and_ on topic (you baited me): yeah, like how python completely solved concurrency & parallelism.
giraffe_lady · 1h ago
Yeah though iirc they did have to rewrite the runtime to get multicore so who knows what sort of tradeoffs they'd have had to make to have had it be like that from the beginning. A lot of what made it good (to the extent it was) in the 2000s was you got a very sophisticated type & module system and a fast compiler without giving up any runtime performance compared to its peers. I don't know if that would have been achievable with its dev resources alongside multicore early. I don't know that it wouldn't either though. Just a big what if all round.

I suspect a larger or at least comparable limitation was essentially pretending windows didn't exist for uh like thirty years. If you knew what you were doing you could cross compile for it but it was not easy. Getting a dev environment running on windows was basically impossible until like five years ago.

The syntax idk I don't have strong feelings about it. I initially recoiled like everyone else of course, but to me style and naming conventions are almost as important and on that front ocaml's are also among the worst in the world lol. Once you get used to it it's kind of endearing how fucked up it is.

toolslive · 1h ago
> ... with its dev resources ... Opening a pull request to the compiler or std lib was also treated with some French love. (I never bothered to open one again after that)
deredede · 1h ago
This looks interesting, it's great to see more machine learning efforts in typed languages.

I'm a bit surprised to see no mention of Owl (https://github.com/owlbarn/owl an older project for scientific computing in OCaml that was resurrected recently), I wonder how they compare.

The Raven README mentions:

> We prioritize developer experience and seamless integration.

so maybe that's one difference — I used Owl on a course project about a decade ago, and while it got the job done, I remember the experience being rather painful compared to Numpy (even though I was more experienced with OCaml than with Python at the time).

FrustratedMonky · 1h ago
Is anybody building things like this using FSharp? It seems like FSharp would have more of the ecosystem for machine learning and AI, than OCaml, yet with the functionality of OCaml.
nextos · 1h ago
F# has bindings to Infer.NET, by MS Research, which is incredibly good for some classes of probabilistic models and very mature.

In particular, it shines on very large models or where fast quasi real-time inference is required.

rybosome · 1h ago
As it happens, I’ve been thinking about a library I’d like to develop in F# as an exercise to learn the language.

I have a hand-rolled proxying inference framework written in Python that is similar in purpose to something like LangChain but much more stripped down, less abstraction. Similarly to many other Python tools, it leverages the reflective capabilities of the language to do things like ask LLMs for responses conforming to a data class, or pass native Python functions as tools. Best of all, it relies on native Python constructs like docstrings to provide additional context to the inference APIs, making clean and well documented code a secondary programming model in a sense.

Perhaps it’s vanity, but at least in Python I find the resulting code quite elegant. I became curious what it would be like to port this to other languages, and surprisingly found that F# would, to my eyes, end up with the most lovely analogue.

Even languages I expected to be expressive and terse, like Haskell, couldn’t express the same ideas as understandably yet concisely as F#.

nickpeterson · 59m ago
It’s a true shame F# isn’t more popular. It’s a great language/runtime combination for doing work quickly, correctly.
cube2222 · 2h ago
Fingers crossed, though I’m not holding my breath for anything taking a sizable bite out of Python in the area of ML/DL.

OCaml seems to be a lovely language based on my limited experience with it. It’s a pity it’s not more popular.

evacchi · 3h ago
so finally someone is actually putting ML in ML

No comments yet