Contemporary Development With Functional Programming

OCaml 4.00.0 on iOS Is Released

September 14, 2012

I’ve just released OCamlXARM 3.1.7, a version of OCaml 4.00.0 for building iOS apps. This is the very latest version of OCaml, which gives you powers other programmers can only envy. But please use your powers for good.

You can download the compiler as a binary package named ocaml-4.00.0+xarm-3.1.7. You can also build OCamlXARM from sources—instructions are on the Compile OCaml for iOS page.

I’ve recently decided that most good ideas start as jokes. When I got the idea of running OCaml on iOS, it seemed slightly crazy. But as things have progressed, it seems more and more sane all the time. Why use less powerful, flexible, and rigorous languages when OCaml runs on iOS just fine? Why spend time worrying about memory management when you can have garbage collection?

OK, well, there are good reasons you might want to use other languages or worry about memory. But I’m going to keep suggesting OCaml anyway, it builds real (occasionally even profitable) iOS apps and lets you concentrate on solving your problem rather than building defenses against all the sources of error in the world.

OCamlXARM runs on OS X and generates apps for iOS using the toolchain that comes with Xcode. I’d say there were three parts of the project:

It requires some trickery to convince OCaml to be a cross compiler. In essence, you want to build the compiler 1½ times. The full build creates a cross compiler whose runtime is for OS X. The half build creates an ARM runtime to be used by the compiled apps.

The majority of the technically difficult work for OCaml 4.00.0 on iOS had already been done by Benedikt Meurer, when he wrote the new ARM code generator for OCaml 4.00.0. I just adapted the output for the iOS assembler. This is partly a textual reformatting problem, and partly an exercise in working around limitations of the iOS assembler.

The ARM code generator of OCaml 4.00.0 is targeted at Linux and its ABI. The ABI of iOS differs in a few ways. For example, I had to make some changes to the code emitted for calling external functions.

Along the way we (OCamlXARM testers and I) encountered a couple of bugs in the base OCaml 4.00.0 release, and some bugs in the iOS toolchain. I imported fixes for the OCaml bugs from the INRIA development repository, and I found workarounds for the iOS toolchain bugs.

You can read about these episodes in my earlier progress reports OCaml 4.00.0 Working on iOS and OCaml 4.00.0 on iOS: Progress Report.

I’d like to thank Benedikt Meurer for help, and the INRIA team for fixing the bugs we reported. I’d also like to thank my colleagues at SEAiq for their help in testing. (The SEAiq guys have recently demonstrated that OCaml threading works under iOS. I’ll post more about this soon.)

If you have comments or questions, please leave them below, or email me at

Posted by: Jeffrey


blog comments powered by Disqus