OCaml for the Masses
queue.acm.org
queue.acm.org
Yaron really does know his stuff when it comes to OCaml. http://ocaml.janestreet.com/?q=node/61
people interested in some great OCaml libraries should check out what Jane street has released to the public:
While the core OCaml language is fun to play around in, a lot of the build tools are scattered across the web and hard to decipher (4 year old blog posts with only half-working code don't help). This aims to remedy that, and I'd appreciate any feedback :).
* It gives you a convenient place to stash extra config options in your project. For example, instead of having to type (and remember!) -tag pkg_oUnit, it's just in the Makefile. You can't forget something that's been saved in a text file!
* It gives you a single point of entry for "other" tools which may be added later -- documentation generation, packaging, installing as a library or Debian package. I personally like all of that recorded in one file so I have to search around less.
* As an expository project, it's helpful to show off clear examples of ocamlbuild itself -- the syntax is different enough that someone just starting out in the language may not be able to grok the documentation enough to just get something running.
Briefly stated, module functors allow you to wrap up a set of functions and types as a module, and state not only which functions and types this module provides but also which functions and types the modules requires. You can plug together module functors with complementary provides and requires, like building with toy bricks.
Many languages support the provides half of this feature (e.g. Java's interfaces) but few support the requires half (Scheme's units are one of the few that come to mind). The advantage of supporting both provides and requires include ability to swap out equivalent implementations of some module, perform massive code abstraction, and to better isolate unit tests without resorting to conditional compilation. (You can quite literally plug a high-level module into a fake lower-level module in order to test the high-level one using one line of code.)
The "language of 2020" will have this, or an equivalent, means of massive abstraction. Or better still, such a mechanism will exist as a separate language unto itself which can work with multiple languages. (Think C-style symbolic linking combined with a .NET ABI.)
OCaml is more verbose than F#. F# is on par with Python.
F# besides having all features of OCaml. (You could (and maybe still can) compile OCaml using F# compiler.) also has some nice extras. Workflows (think monads in Haskel). Workflows in turn used to implement Asynchronous Workflows, and mailbox thread processing. So you get Erlang style multithreading.
Another point for F#: since it's on .Net and .Net actually runs on multicore machines the way one would think it should run. OCaml on the other hand has garbage collection that does not play with multicore very well.
Last but not least: F# can call any .Net function or create any .Net object -> you have access to a lots of things out of the box. F# - batteries included; OCaml - batteries are not included.
[Edit - spelling and formatting]
Also F# is not all of Ocaml. To mind, it lacks functors, ocaml strength modules and polymorphic variants. Ocaml also has the potential to be faster. At least in the single core case.
F# can only go as fast as .NET. Compiled OCaml though is very fast - I completely agree with you.
Some important features, such as modules, are missing in F#. I suppose the intention is to replace them by interfaces and classes, but modules in particular are an important omission that makes me prefer OCaml (though I like both ;)).
Of course, F# adds lots of things; here's a nice summary: http://stackoverflow.com/questions/179492/f-and-ocaml/248527...
[1] http://citeseer.ist.psu.edu/icons/pdf.gif;jsessionid=FF06FC4...
If you go to the article at the bottom it lists some limitations. Libraries, tooling and proper parallelism including in GC. Also IMO F# ties OOP with functional better, on par with Scala.
If you weight these against F#'s weaknesses: lack of full modules and functors, tied to .net and mono / non native code generation and they come up being more of an issue then you would prefer F#. Which is the choice I ended up making.
http://cs.ioc.ee/~keiko/FSharp.html
http://news.ycombinator.com/item?id=1826564
http://stackoverflow.com/questions/4507600/extension-techniq...
http://stackoverflow.com/questions/4239121/code-compatibilit...
http://stackoverflow.com/questions/6390665/hesitating-betwee...
[1]: http://video.google.com/videoplay?docid=-2336889538700185341
It would be pretty cool if someone made a node.js (event lib) like web server for Ocaml.
There's also an OCaml-to-Javascript compiler.
It's not just about functional programming being powerful and concise and awesome, even though it is those things. (Mostly, that is. Functional programming, taken too far, can be incomprehensible.)
Ocaml's a very simple language: a bare-bones skeleton for what a 2020 language will look like, a functional C. I don't intend to claim that everyone should drop their favorite languages and switch to ML, but it's important to grok the idea of ML to get a taste for: (1) higher-order functions (instead of objects) as the default abstraction when mutability's not needed, and (2) the power of strong, static typing. The actual "language of 2020" won't be this Ocaml (no multicore support) implementation and probably not Ocaml at all, but it will look a lot like Ocaml, Haskell, and Scala.
Let me bring out one snippet:
Reading code was part of the firm's approach to risk from before we had written our first line of OCaml. Early on, a couple of the most senior traders (including one of the founders) committed to reading every line of code that went into the core trading systems, before those systems went into production.
That's not bullshit. A smart person with a general sense of algorithms, but who's not necessarily a full-time programmer, can read and understand most OCaml code. In C++ this would be impossible; you'd need a C++ expert just to make sure you're not going to get impaled by undefined behavior.
What makes OCaml awesome is that it's the only language I've encountered (Haskell and Scala may have this property; insufficient exposure) where reading average-case code is fun. Haskell is a great language as well, but it seems to be optimized for writers of code; Ocaml's optimized for readers. Yes, there's horrid Ocaml code out there and there's beautiful code in lesser languages, but Ocaml is the only language I've ever encountered where 50th-percentile code looks attractive. The consequence is that people do read code. Sometimes, just for fun. (Yes, imagine that.) I learned a hell of a lot about programming when I was working in Ocaml simply because I enjoyed reading the code. Average-case C++ code is never fun to read, and what matters in a professional environment is not what the language makes possible, but what average code actually ends up looking like.
If you're not familiar in detail with the benefits of functional programming and strong static typing, read this article. Read it 3 times, even.