Why is virt-builder written in OCaml?
rwmj.wordpress.com
rwmj.wordpress.com
http://libguestfs.org/guestfs-ocaml.3.html
Overall, great article and great code. Let's keep in mind that SML is typically taught to entry-level CS students (some of them with no programming experience) at universities like CMU, where often a term project might actually be an ML compiler in ML. It's not a terribly complex language and some limitations (which I am not going to state here) aside it has a great use to play.
It should be noted that XenServer also uses OCaml. While it's not really fair to compare Go with OCaml (the language roots are vastly different as are the philosophies -- aside from the idea that "static typing shouldn't mean typing so much you generate static electricity") both seem to do best in the "userland systems programming" niche -- that awkward place where C++ is needlessly painful, Java is ill-fitted, and python/etc... simply inappropriate.
https://github.com/libguestfs/libguestfs/tree/master/generat...
For an API that has 400 or so calls accessible through a dozen different programming languages, this makes sense. The bindings in each language are never out of date or wrong (except of course they can have a systematic bug, but those are much easier to fix).
This also makes it very easy to generate alternate "views" of the same API, like OCaml module vs OO views.
Also virt-builder is very procedural: https://github.com/libguestfs/libguestfs/blob/master/builder... It's "do this, then run this, and if this condition is true do something else". OCaml's strengths here are its brevity, speed and safety. No complicated features are used, eg. no functors, no difficult use of functions as first-class objects ...
(I'm not actually a fan of functors; I think they obscure the flow of the code, in the same way as using inheritance in OO).
While functors aren't something to us every day, aren't they more of an equivalent to the Decorator pattern in OO (which is more about composition and inheritance of interfaces as opposed to inheritance of concrete implementations which I agree is something to avoid)?
That said, I think I see what you mean -- I've found myself using functors needlessly because I've previously used adapters in their place in Java; instead, it may have been for it for me to ask myself what the real problem I'm trying to solve is.
We're somewhat limited in terms of dependencies. We can add a dependency, but it needs to be available on all platforms we support (Fedora, Debian, Arch, SuSE, Gentoo, OS X would be the main ones). Of course this is an argument against OCaml, but so far we've been fine needing only a handful of libraries and liberally calling out to C.
Huh? FORTH is one of the most simple programming languages around.
My anecdata tells me that Go's types are sufficient (and sometimes even handy), error handling everywhere helps more than it hurts (and is easily ignored if you want to), and is very much not a functional language. And I would disagree with the notion that C is, on average, well-understood given how widely available it is (a nicer way of saying that C is an easy language for anyone to misunderstand). Go is comparatively simpler to 'get right' -- in my experience
Again, this is all very subjective. Still, I don't see how flaming Go alone helps highlight OCaml's advantages and contrast their tradeoffs.
Deleted comment
You seem pretty adamant -- what makes you think that? I think it's quite the opposite: the language and the community never felt as alive and thriving as they are right now.
Last time I looked into it, the answer was no. I vaguely recall it having to do with stdlib not being thread safe, concurrency issues with the GC, and some other stuff...
- pervasive use of laziness makes space utilization hard to reason about
- Highly complex runtime (mostly due to the need to work around laziness), which makes it harder to trust the correctness of the overall system and to and understand performance
- Significantly more complicated type system, which has its ups and downs. It surely makes the language more complicated to learn in and use in many cases. Benjamin Pierce, no slouch himself, has pointed out that he sometimes has to go read a research paper or two to understand some new library.
- Enforced type-level separation between pure and unpure code, which again, has its ups and downs.
Haskell is a great language. But it surely doesn't dominate OCaml.
And the OCaml community is doing quite well of late, as far as I can tell. There's a lot of new energy in the last few years, with great progress in both the core language and in the surrounding infrastructure.
OCaml is almost 20 years old now, which is about the right amount of time to start trusting a language for mission critical code :)
Some of our experiences in Xen that we wrote up for ICFP 2010: http://anil.recoil.org/papers/2010-icfp-xen.pdf
And lots of source code: https://github.com/xapi-project https://github.com/mirage