OCaml's domains


#1

Are the domains that OCaml excel at, and the ones that are a poor-fit documented anywhere?

Also, are there any efforts to expand those domains, similar to the way Rust is doing with their Domain Working Groups?


#2

I’m not sure what domains OCaml is a poor fit for. The Mirage people have even managed to build an operating system largely in OCaml. That said, I’d say that one obvious ill fit would be anything where garbage collection pauses are a really big problem — say in tight real time systems. Mostly, though, I think OCaml is surprisingly good at a very wide variety of application domains. The compiled code is quite fast, the libraries are good, the community is fabulous, and mostly I complain about bad documentation and the fact that certain features I’d really love are a long way off.


#3

There’s this (sadly way outdated) State of the OCaml Ecosystem (2015) which listed application domains, their related technologies, and assign a rating to each. Perhaps it would be great to keep it up to date.


#4

In general, OCaml will be a poor fit where multicore performance is needed, at least until the multicore branch goes mainstream. This isn’t terrible though since python, ruby, and javascript are all single core, and OCaml handily beats all of them performance-wise. There is some basic support for multi-process parallelism but it’s awkward.

Additionally, OCaml’s default representation of floating point values is not efficient. Heavy floating-point calculations will not be great when done in OCaml code (though Flambda is changing that gradually). However, Owl has been very successful in integrating numpy-like methods (ie. calling out to highly efficient C code when needed) for vectorized operations. So while I would not have recommended OCaml for simulations and such, I’m not sure that’s true anymore with Owl.

So in general, multicore-dependent programs are not an ideal fit (yet): operating systems (non-unikernel), game engines and such.


#5

I am particularly interested in web servers, cloud-native apps (both API backends and workers), and CLIs that interact with external APIs. I encountered challenges developing anything useful in those domains due to lack of libraries, or immature/unmaintained ones.

As far as I can tell, OCaml does not support HTTP2, gRPC, Google Cloud Platform, NATS…
Some core infrastructure projects such as elasticsearch and redis have outdated or unmaintained libraries. And other projects, like graphql, have incomplete implementations with no production users. Even something as simple as the latest YAML standard (1.2) is not supported in OCaml. Overall, the ecosystem is so minuscule which makes introducing OCaml a dangerous business proposition.

I would love to use OCaml more. We’re already planning to introduce it in the frontend with ReasonML, but I don’t see us using it in the backend yet. That’s why it would be great if the OCaml community steals ideas from Rust on building and expanding the ecosystem because OCaml desperately needs more people involved.


#6

As the author of the ocaml-yaml library, I can assure you that there is nothing simple about Yaml :slight_smile: Out of curiosity, why do you need Yaml 1.2? Most real world use of Yaml I’ve seen is the JSON-compatible core, which is more than satisfied by the existing Yaml 1.1 implementation in OCaml.

We are liberally heading in this direction with the ongoing OCaml Platform development (tools such as Dune and opam2 are steadily maturing). We’d also welcome contributions of library implementations of (e.g.) http2 into frameworks such as cohttp.


#7

When I was first learning OCaml, I decided to learn by building a CLI tool for our microservices. The CLI failed to parse a YAML file outputted by ksonnet. I honestly did not investigate at the time if it was really a YAML 1.2 issue, but I did verify that it’s valid YAML, so I assumed it’s a 1.2 compatibility issue.

It’s not a tooling problem. It’s mostly about stewardship of the OCaml language. I’ve joined the Rust and OCaml communities at the same time, and I’ve been blown away how different the communities are in terms of moving their respective language forward, and growing their ecosystems. I really suggest leaders in the OCaml community perusing the internal Rust discourse and subscribing to Rust weekly. Rust has a vibrant growing community. They are able to do that because some of their core team members have extensive experience building communities. Without a coordinated effort, OCaml is going to remain a fringe language used mostly by Jane Street, academics, and a few smaller companies.

Shouldn’t the OCaml community focus on http/af instead? cohttp has documented scalability problems.


#8

I’ve used our OCaml implementation with quite a few K8s/Docker/Buildkite Yaml combinations, so this just sounds like a straightforward bug somewhere. I’d be surprised if it’s Yaml 1.2 specific.

Out of curiosity, where do you think this particular Discourse setup came from? :slight_smile: One thing to bear in mind is that Rust is a very new language, and so doesn’t have quite the same multi-decade level of backwards compatibility and compatibility needs as OCaml. So while we move at a slower pace, we are indeed moving in the right direction. What we lack are volunteers to step up and assist with elements of the community stewardship – for example, an effort to collect an OCaml Monthly on this forum would be a huge boost to us.

Scalability bottlenecks are easily fixed with a some minds with spare time on the problem. Both libraries also have different focusses (http/af is Unix only, Cohttp compiles to JavaScript/unikernels/etc). What both libraries lack are motivated maintainers who will advance them. New contributors are extremely welcome on this front!


#9

I’m not exactly sure what you mean by that. But before you spread misconceptions, let’s be a bit more precise.

OCaml’s float type are IEEE-754 64 bit double precision binary floating point number. There is no support for 32 bit single precision numbers.

While individual float values will in general be boxed when you pass them across functions they are not locally when you perform computations (and this long before flambda existed). floats are also special cased and stored unboxed in the float array type (though that may change in the future as it seems the feature is controversial among compiler hackers).

I believe this old document about numerical computations in OCaml is still conservatively accurate (things may have however have improved e.g. when using flambda).


#10

I appreciate the details and the link, but I think my general summary was correct. OCaml would not be my choice for programs with heavy float usage. You can’t even write efficient recursive functions (one of the main paradigms of functional programming) with floats – even with flambda. If I wanted to use for/while loops everywhere, I would have stuck with another language.

Clearly, floating point usage was not the main consideration when designing OCaml – otherwise, we could have used something like nan tagging (which of course has its own trade-offs).


#11

I am going to both agree with you and disagree. I fully agree that community building and a focus on strategic projects will help the community a lot. I’m going to disagree that this is something that is likely to happen because people who are very interested in engineering on the language decide to spend most of their time learning how to build a community. This is doubly true because such people usually prefer working on technical problems. :slight_smile: Mostly a community gets built because of a virtuous circle, where strategic improvements drive new adopters which drive new strategic improvements.


#12

A side note: (hand) performance optimization of FP heavy code often requires selecting which floating point format to use for which case. Precision vs. cycles tradeoffs are quite real on some architectures.


#13

Rust is a new system programming language (usually unpopular) that’s attracting developers from various communities. It has libraries for everything that I need. Those libraries usually have great documentation and many contributors. OCaml needs a coordinated and deliberate effort to match that. A lot of developers are probably dropping out because they discover that many packages are missing or have serious quality issues. The current status does not encourage contribution. The excitement about the OCaml language is dampened by the lack of packages, fragmentation, and slow pace of progress.


#14

The first thing I want to note is that things have really improved in the OCaml space. By a lot. People new to the language aren’t really aware of this, but it’s true. Most of this I attribute to OCaml labs and the great people that have come out of there, a few companies’ investment in the community, and additionally now we’re experiencing a bonus Renaissance due to ReasonML.

At the same time, I think the main thing holding OCaml back (aside from lack of people) is a certain culture that’s pervasive, and is very common among older programmers: “Who needs this new thing? My thing works just fine for me and there’s no need to change it.” This is followed up by “You want to do this? Go implement it on your own and prove to me it’s worthwhile before I even consider it.”

The first problem is that this mentality ultimately saps the energy of people who want to improve things until they give up and move on, and all you’re left with is a self-selection for the same old attitude and culture. The other problem is that without change - without advancing with the time - you lose out on the most important thing, which is new users in the ecosystem. Users are everything to a language.

It took a long while until the community was convinced to try Discourse. Even now, there are old-time OCamlers who don’t show up here – who are still clinging to the old OCaml mailing list. Was the old list ‘good enough’? Well, it was functional, but there are many advantages to Discourse, the chief one of which being that you now can attract new users who see a live, rather than a dying, community.

I would argue that the same thing needs to happen to the IRC channel. Is IRC decent? Sure. But you’re isolating yourself from the world, and you need the world a lot more than it needs you. OCaml can’t afford to look like the old man shouting at young people to get off his lawn. It’s not a good look, and it doesn’t attract anybody. How many people have not been exposed to OCaml because they didn’t stumble on a live discussion with knowledgeable users? I’d wager it’s a lot.

As an example of the opposite culture, if you step into the Rust chat, you can’t help but be attracted to it. They’re discussing RFCs for language features in the forum, for goodness’ sake! Conversations that happen in hallways or on private email messages in the OCaml world are taking place out in the open, and interested people can get involved in whatever interests them. You can’t beat that. That infuses the community with energy.

And lest you think this is too hard to replicate, just look at ReasonML. Sure, they’re just designing a front-end, but the energy is there because the process is open, and they have an attitude of change and growth that’s infectious.

I also want to mention that I think backwards compatibility can be overrated. I appreciate solid backwards-compatibility as much as the next person, but backwards-compatibility is most important when you have a large audience. When you have a small audience, your existing projects break down into a mix of a majority of dead and unmaintained projects left behind by people who mostly abandoned the language, and modern projects that are really interested in the changes you want to make, and would update their code to support it because they care about the future of the language. The point is, if making changes will grow your ecosystem significantly, potentially all the backwards-compatible projects that now exist will be a drop in the ocean of projects that will eventually exist.


#15

Well, I agree that it’s nice when people are enthusiastic, and when they can contribute design decisions and RFCs and whatnot. Rust seems amazing indeed, but as pointed out earlier it’s a brand new language that has the huge advantage of hindsight.

“Who needs this new thing? My thing works just fine for me and there’s no need to change it.”

What are you talking about? Have you seen the statistics about packages migrating to dune, for example? People are ready to move to new alternatives when they clearly seem better. If you have concrete examples of that behavior I’d like to hear them.

I would argue that the same thing needs to happen to the IRC channel.

What, should I leave IRC (and the friends I have there) just because there are newer, shinier things? What alternative would you even suggest (please don’t say “slack”)? Discourse is cool and seems to be welcoming to newcomers, that doesn’t mean we need to kill everything else.

I also want to mention that I think backwards compatibility can be overrated.

Will you please rewrite my projects on every compatibility breakage, then? The community is not very big but there’s a lot of existing OCaml code; in particular, but not only, in academia, where manpower is scarce. If you break compatibility you destroy all this work. And by the way, note that rust also makes big promises on retrocompatibility.


#16

Yes, but Dune had to be built out of whole cloth and given to the community. Were it not for Jane Street’s graciousness, we would still be in the build system mess, with each person clinging to their own system. A build system had to go viral to save us from ourselves, and the energy for that viral transition came from the younger people in the community.

I’m surprised that you would say this, given your difficulty in getting changes into the stdlib or Batteries to the point that you had to do exactly what I mentioned – you went and built a thing entirely from scratch (Containers) to prove it could be done differently. This isn’t a scalable way to do this – not everyone can build an stdlib from scratch.

We should be open to trying out a new tool. If it doesn’t work out, ok that’s fine. But the overwhelming response is ‘get off my lawn’ (though as I mentioned, it’s changing recently). Your friends should all migrate with you, because there is a whole world of people waiting you meet you guys.

This is more of a side point. Like I said, I appreciate backwards compatibility. But fear of breaking things can be paralyzing, and all I’m saying is the community almost entirely errs on the side of being conservative in this matter. We can often come up with tools to translate old code to new (as we do now with ppx, or Reason does with refmt), and yet backwards compatibility always dominates. Not saying it shouldn’t win out most of the time, just that we could temper it with a forward-facing understanding of the potential for exponential growth.


#17

As a part of the Reason community I have to say that an open process is by no means an integral part of the Reason or Reason React project (except for few instances when the public opinion was consulted).

Reason has grown because of its Discord channel and Reason’s creators who burned half of their productive time to respond to simple and repetitive questions. In another words it’s a maniacal focus on new people and people who can convert from javascript (look syntax).

Currently the Reason community is a self propelling machine powered by mostly novice people who mutually help each other. There’s definitely something to the Reason community but it’s not openness. I’d say it’s more patience of the people who started it and their incredible responsiveness who set the tone.

That said, in general hard tasks (like Bucklescript) lack contributors (a similar situation).

I believe this is right. I am not sure if people who maintain this forum have such experience. Matter of fact one of the hardest things is separating such mostly unproductive and noisy discussions from ones that can have substance. I’d say that what should be a common practice is forcefully moving discussions which get too off topic into new threads. This sub-thread for instance could be called “I want more and better libraries”. “What you tolerate is what you become.”


Community Building
#18

While I think new and shiny methods of discussion (such as the discourse forum) are great, I have some reserves about realtime chat options. More particularly, IRC has the great advantage that there are many interfaces/frontend you can use, such as weechat, irssi, etc… many of them open source, it doesn’t require subscription, and it’s well adapted for multiple channels and server, i.e. you can very easily access multiple communities with the same tool.

Now if every community turns to some proprietary chat service, you need to get used to a different interface for each community, you may be required to create accounts on proprietary services, you may have to install the corresponding apps on you smartphone (with all the permission and privacy problems it can entail), etc… Personally, I find this to be more of a problem than the technical aspect of figuring out how to connect to IRC.


#19

Although I generally agree that it is good to try new things, in the case of the IRC channel it has proven useful to me a couple of times, and I’m suffering from severe chat client overload. I have far too many and don’t want more new ones. :frowning:

(This is more a factor of the fact that the instant messaging world hasn’t adopted a single reasonable standard than anything to do with OCaml. I shudder to think what it would be like if email was like this and we didn’t have SMTP and IMAP.)


#20

I do use OCaml for scientific computations (mostly solving ODE/PDE and nonlinear optimization) and this has never been an issue. In my case (research), being able to quickly change de code to try new ideas is very important and OCaml shines at that. The small set of available scientific libraries is more a problem than raw speed. That being said, more float efficiency is good (and I hope flambda keeps improving that) but that should not deter you from writing scientific code in OCaml.