Look, I love OCaml and it's my favorite language syntax-wise, but the real big elephant in the room is not its JS-backend maturity. Rather it doesn't have kernel thread support...all threads are user-level just like Python due to a global lock for garbage collection. This means threads do not run concurrently across multiple cores. This is UNACCEPTABLE in 2014 - roughly 8 years since processors went multi-core. Intel is talking about having hundreds of cores on a single die by next decade and having programs that can't take advantage of that is extremely limiting.
Xavier Leroy (the creator of OCaml) and his team at INRIA didn't think this was a big deal because when they were writing this stuff, processors were single core and had been since the beginning. Sure there were multiprocessor machines (not the same as multicore as there are multiple die), but those were only meant for servers/workstations. OCaml seemed very promising around 2006, the peak and end of the single core era with the Intel Pentium 4. What made OCaml so impressive was not only was it this beautifully simple, high-level functional language, but that the native compiler produced very fast code that was comparable to C/C++ performance. However, as multicore processors were introduced (Intel Core, Core 2), not having this capability made writing new code in OCaml less appealing. There are solutions like MPI, but that's lame. The same excuses you hear in the Python world about having true multithreading you hear in the OCaml world. Microsoft was able to do it with F#, which is essentially a clone of Caml by targeting their .NET CLR. Haskell is able to do it with GHC.
I still think OCaml is a wonderful language -- not having true multithreading doesn't make it useless. However, to me it has become more like a statically-typed Python which I can use for scripting. Having to use hacks like MPI to do multicore processing is a huge turn off in a multicore world. This is again nothing against the language, but the standard implementation needs a concurrent garbage collector and kernel threads. Otherwise I think OCaml may be doomed to irrelevance in the long run, which would be truly sad.
That being said you can still use multiple cores by using multiple processes, and that doesn't necesarelly imply MPI.
OCamlNet (and probably some other libraries) provide a way to communicate between multiple OCaml processes.
Good to see work is being done on it, but until it's in the main implementation for at least a year...I wouldn't trust it on anything that matters.
The advantage of kernel threads is that they have way less overhead than a process (both in context size as well as more efficient memory caching at processor and OS level)...though more than a user-level thread. If there isn't any sort of message passing between two processes, the only mechanism I can think of of sharing data is shared memory (i.e and mmap) which is just as efficient as threads sharing the same process heap...but awkward (yes there are sockets, file IO, signals, queues, etc, but not as efficient). Even if OCaml provides a way to abstract that to be more palatable + safe -- my argument is that in a multicore world, kernel threads must be a first class citizen and the programmer shouldn't have to resort to tricks to harness it -- otherwise it's a major flaw that is going to prevent future adaptation. Also, as the number of cores increase, this is going to matter more and more...so hopefully this stuff gets out in the wild soon.
The multithreading situation in Haskell is pretty exciting. Simon Marlow's Parallel and Concurrent Programming in Haskell is the best new programming book I've picked up in a long time. And there are new developments since he wrote it (http://www.haskellcast.com/episode/004-simon-marlow-on-paral...). It would be a shame to give all that up.
What's interesting about Haskell in this regard is due to the pure functional nature, the Church-Rosser theorem applies...every function call could be executed in its own thread without protecting any resources with locks/mutexes/etc! I haven't studied the compiler design of Haskell, do you know if the compiler can delegate function calls to a thread pool automatically?
It won't though. Because it'll still be a decade behind haskell. People want more than just "ok, you can use multiple OS threads now". They want a concurrent IO manager, painless and seemless multiplexing of low cost green threads over OS threads, and high level concurrency and parallelism constructs. It is going to take a long time for ocaml to catch up to haskell in this department, and who knows what haskell is going to be offering by then.
I'll update the post once this traffic calms down a bit :)
It is a mature yet actively developed whole program optimized, strongly typed, polymorphic, ML like language that can interact effortlessly with C and C++ and has coroutines and threads baked in, although use of threads is somewhat discouraged. It has type-classes as well as modules. Functions written in it may be exported as a CPython module. This might be useful if one wants to gradually transition from a Python based src tree.
It uses a mix of lazy and eager evaluation for performance and compiles down to C++. Execution speed is comparable to hand written C++, mostly better. Its grammar is programmable in the sense that it is loaded as a library. So in the same way that languages may acquire libraries, Felix may acquire domain specific syntax.
It is also mostly a one man effort but with a feverish pace of development so it comes with its associated advantages and disadvantages.
The author likes to call it a scripting language but it really is a full-fledged statically compiled language with a single push button build-and-execute command. http://felix-lang.org/ The "fastest" claim is a bit playful and tongue in cheek, but it is indeed remarkably fast.
Have you actually used Felix? I agree it's a neat language but it felt to me like I'd really have to come up to speed on C++ to make much use of it. It's "FFI" is basically embedded strings of C++ source.
You can of course inline C++ snippets in Felix code as you mentioned, but that is not the only way to talk to C++. Felix allows you to create a Felix object from a C++ object (and the reverse) with minimal glue. Take a look here http://felix-lang.org/share/src/web/tut/cbind_index.fdoc.
With this two styles the boundary between Felix and C++ can be very fluid. It does not incur the typical efficiency hit of a dynamically loaded FFI, although it does allow dynamically loading shared libraries too.
If you dont want to use C++ libraries and classes from Felix, you dont need to know C++ to use Felix.
I've found it interesting that OCaml hasn't had more interest given the amount of recent momentum in Haskell.
Haskell is an Ivory Tower. The features that generally draw one to the language also tend to be the things that eventually push one away. Haskell has grown a lot over the years however as the language evolves to allow general programming within a pure framework.
OCaml on the other hand tends to make a compromise, acknowledging that the programmer occasionally needs a different tool for the job. OCaml allows the programmer to opt into things like mutability and objected oriented code when the need arises. These compromises can also be seen as the languages downside however.
I find it interesting that the driver for the author into OCaml is JavsScript... but it's nice to see OCaml come up a bit more often. :)
I feel it's similar to any competitive environment: differentiation requires making strong tradeoffs. Haskell's choice of tradeoffs---while initially very ivory tower---have led to to become a strongly differentiated language. You not only learn how HM typing and full commitment FP feel, but also how to structure code purely, compose effects, and abuse laziness.
So for the very same reasons you give---Haskell has made fewer tradeoffs for "practical" programming---Haskell has become something valuable and interesting. On those tides the community has grown.
Another big obstacle was that the INRIA license effectively prevents forking the language (you can only distribute modified compilers as original source + patch, not as eg a github repo) so for a long time there was a bottleneck on the language evolution. Lots of useful extensions (eg delimited continuations, staging) wilted and died because of that.
The rise of OcamlPro and Ocaml Labs does give me hope for the future of the language. There is already renewed momentum behind fixing packaging and handling multicore.
Now if someone would just figure out ad-hoc polymorphism (just pick one of the dozens of propasals) and maybe even document camlp4/5....
You are acknowledging that you are wrong without even noticing. No, haskell is not an "ivory tower". It is a very practical, useful language. That is precisely the reason it has gained so much momentum and usage. Ocaml had more users than haskell back in the mid 00s. Now haskell absolutely dwarfs ocaml. The reason ocaml doesn't get more interest pigging backing off of haskell is that there is no reason to use ocaml over haskell.
For me Scala has been the not-quite-as-good-as-haskell-but-more-industrially-acceptable language. I'd be very interested to see a more neutral comparison of functional languages for compile-to-JS, because if anything Haskell seems more popular for that - I hadn't heard anything about compiling OCaml to JS before this.
I just started at a Microsoft shop a few months ago (first time for everything), and I actually quite like F#, now that I've had a little while to play with it. It's a good contender for the NQAGAHBMIAL throne.
Having used CMUCL/SBCL for a while, I always found ocaml's "well, you can compile your code, but then you can't run it in the REPL" to be off-putting. (For my purposes the CLR JIT compiler for F# is good enough.)
I've put a lot of work into a compile-to-JS evaluation for my day job. It's not suitable for public consumption, but of our top 5 choices:
- ScalaJS is still experimental.
- OCaml had a viable project in about half the time I estimated it would take.
And on a personal note, Scala seemed great at first but after SML/OCaml I find the number of times that I have to tell the type checker what I'm doing immensely frustrating :)
Scalaz helps with the idioms but without the purity garuantees you miss out on all the optimizations and verifiability.
The java collections & libraries don't help me when I need to manage my own memory. I've spent entirely too much time in the unsafe package because the JVM doesn't allow me to do cheap ffi unlike Haskell or even Microsoft's CLI.
OCaml is actually taught in the second level computer science course at my university. I think its a great language for learning topics like recursion especially with its pattern matching. Its also a great intro to functional programming
This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line.
The only real reason that I can see to choose OCaml over Haskell is that if you learn OCaml, you might be able to work at Jane Street. Is there a strong argument for abandoning my Haskell-ing for OCaml?
Would you care to share an example? I've never encountered a justifiable need to write ;; outside the REPL. The only uses of ;; I've encountered "in the wild" were hardly reasonable: essentially top-level code that was not wrapped in a "let () = ..." statement.
I don't recall seeing that recommendation before this thread. That may just be my blindness in skimming things too quickly. In any case, I think it indicates a wart in the language when you have to wrap everything in otherwise useless let blocks just to get it to parse.
For reference, here is the tutorial's example reformatted in a more reasonable way:
let rec iterate r x_init i =
if i = 1 then x_init
let x = iterate r x_init (i - 1) in
r *. x *. (1.0 -. x)
let main () =
open_graph " 640x480";
for x = 0 to 639 do
let r = 4.0 *. (float_of_int x) /. 640.0 in
for i = 0 to 39 do
let x_init = Random.float 1.0 in
let x_final = iterate r x_init 500 in
let y = int_of_float (x_final *. 480.) in
Graphics.plot x y
ignore (read_line ())
let () = main ()
After which, if you've been in the industry for a decade or two, you will probably decide that you'd better stop wasting your time on that particular language. Besides. It just looks ugly. Almost as ugly as perl.
The Graphics module is a core Ocaml library that is always available. In order to use it, it must be linked on the command line, similar to many other languages. Installing an unrelated OpenGL binding didn't magically make "ocaml o.ml" work. Based on this and the obvious trolling of your final paragraph, I'm hesitant to believe anything you said is true.
Seriously. You are so biased that it is easier for you to believe that other people are downright lying than to accept inconvenient truth. I was running it in the interpreted mode. Isn't that how one is supposed to run tutorials code? And obviously I've added the following:
into the file first. And forgot about it, when writing the post. So no magic here. "Beautiful" syntax by the way.
And no, I wasn't trolling. I just wanted to see what that recursion would do. The code is not exactly crystal clear there, with names like start_x and such. But it really did not work. And the syntax is really ugly. And you can believe what you like.
Dont judge syntax when you are new to a language. Few syntaxes have the tendency to never grow on you, but it is surprising how most do, even when your first impressions were pretty bad. Remarkable abilities of the human brain !
Tried it here and it worked, both on Arch Linux with OCaml 4.01.0 and a clean Ubuntu/12.04 with OCaml 3.12.1:
$ ocaml graphics.cma test.ml
Debian splits OCaml into two packages: ocaml-nox (no X) and ocaml (everything). Make sure you're not using the nox version, and make sure you have an X server available (i.e. you're not running it on a headless server or something).
Still, "fatal I/O error" is a terrible error message.
Ocaml was always the more pragmatic language and for a long time the implementation was significantly faster than anything SML offered. MLton came along very late in the game and offers excellent performance, but doesn't support separate compilation.
what saddens me is that aliceml [https://www.ps.uni-saarland.de/alice/] seems to have died. i've kept it vaguely in the back of my mind as "this looks like a very pleasant language, and as soon as i have a problem in its sweet spot i'll give it a good look", but the last time i went to look at it i realised the last mailing list post was in 2012, and the last home page update in 2007.
Considering how strongly opposed the author is to dynamic typing, I'm actually kind of surprised they'd consider OCaml's type system to be acceptable.
Technically, yes, it's a statically typed system. But its use of structural typing instead of nominative typing effectively means it takes half the compiler assistance you can get out of static type checking and chucks it out the window. Using structural typing means that a type is nothing more than the sum of its parts; nominative typing makes it possible to add further specificity to types by naming them. This is huge. A language that doesn't do this is a language that can't be taught to understand the difference between 12 meters and 12 Newtons.
You may be confused by the fact that the type system will notice the equivalence of two types if the implementations of both are public eg
module M =
type newtons = int
let inc some_newtons = some_newtons + 1
type newtons = int
val inc : newtons -> newtons
M.inc 1 (* this works *)
module M =
type newtons = int
let inc some_newtons = some_newtons + 1
let in_newtons x = x
val inc : newtons -> newtons
val in_newtons : int -> newtons
M.inc 1 (* type error *)
M.inc (in_newtons 1) (* this works *)
The use of hidden types in OCaml gives far better control over encapsulation and implementation hiding than any over language I've used.
Also, only some things in OCaml are structurally typed (modules, objects, polymorphic vairants), others are not (records, variants). For example:
# type meters = I of int;;
type meters = I of int
# let meters i = I i;;
val meters : int -> meters = <fun>
# type newtons = I of int;;
type newtons = I of int
# let newtons i = I i;;
val newtons : int -> newtons = <fun>
# let f b = if b then newtons 12 else meters 12;;
let f b = if b then newtons 12 else meters 12;;
Error: This expression has type meters but an expression was expected of type
If you don't have a particular goal in mind (ie, "I work at Jane Street and need to be compatible with our existing code"), there are a number of other factors in the OCaml vs. Haskell discussion that are far more important.
> JS is the only realistic way to write web apps
 I'm not sure if this is a flamewar topic for car nerds - my point is to pick two high-end luxury cars that are both well-respected and each have their own merits.
> It sounds like you have a very language-centric view of the world.
> Having a solid implementation for your target platform is very good reason to pick a language.
I'm not sure where you got that out of my comment; it was exactly the opposite.
Okay, sounds like a misunderstanding about what "web app" means. Sorry about that!
I don't know whether OCaml is ahead of Haskell in this space. I've tinkered with Elm a little bit.
Car metaphors don't always match well with the situations they try to illustrate. Obviously if you had the chance to be offered either one of these two cars, you'd probably try them out and pick the one you feel the most comfortable with, but also which would best fit your needs. If all other factors have been weighted, and it boils down to the number of cup holders, would you stop there short of making a choice, because of the apparent superficiality of the argument? The author expressed his interest in both languages, and brought other arguments than just the js one.
See, from what I took from the article, is that maybe it would make for a really solid client side web application language. On the other end of this, i feel like server side languages are moving more into the direction of multi-core support, i.e. Rust, Golang, Erlang... oCamel could fit nicely as a client-side web application language for DOM manipulation, like ClojureScript -- at least that's my take on it, but it really couldn't compete with the newer multi-core languages -- speedwise.
I'm curious about this as well so I did some searching.
There are other options, this  article outlines a number of them as a greater overview of both server and client side programming with Haskell. I also found an intriguing article  on the Haskell site but it appears to be out of date, referencing libraries that are no longer in development.
I've played with Elm for a toy project before and I do have high hopes for it. I also think it's the greatest monad tutorial ever - you don't truly miss them until they're gone.
(To clarify: At the time that I last used Elm, the Signal type was a functor, but was intentionally being kept from being a monad for design reasons. Working around this restriction tought me a lot on why I needed monads.
I didn't really understand applicative functors until I was playing with Elm. Working with Signals was pretty fun, and when I found out they were applicative functors, it was like a light bulb going off above my head.
Elm is a really fun way to start exploring purely functional programming.
I assure you that it's not a trick question, just a poorly worded one.
Imagine that I'm making a page that converts meters to millimeters. The obvious part of the haskell code is
convert :: Double -> Double
convert = 1000 *
How do those "to js" code generator behave when used together with frameworks like backbone or angular ?
I know things like typescript or dart have special versions of the framworks, but i'm curious to know how the ocaml to js tools behave ( since i've searched for a decent strongly typed server side technology for years, that would be an argument for me to try that language).
I don't know about OCaml, but generally speaking, there is a foreign function calling interface. You'd typically use it for integrating with large standalone codebases you don't want to rewrite (say, CodeMirror) but typically not for frameworky things. If you're going to use the same UI framework there's not much point in switching languages.
Here's the plan -- eliminate perl, python, ruby, php or java or any slow-starting jvm-based language(the featureless landscape of clojure for example), and use just bash, sed, awk, ocaml(to replace the fear of 'C'), and we can also do f# on windows, so there would be crossover between the worlds and peace throughout the land.