Psellos
Life So Short, the Craft So Long to Learn

OCaml Programming

In this most recent millennium we’ve done most of our development in the functional programming language OCaml. It has power, flexibility, static type safety, and is compiled both to efficient native code (for many architectures) and to JavaScript. The OCaml home page is www.ocaml.org.

Quite a few years ago we released two card game apps for iOS written in OCaml, Master Schnapsen/66 and Cassino. Although we didn’t succeed in our hope of sparking a worldwide craze for developing iOS apps in OCaml—or for playing the game Schnapsen—we still had a fantastic time getting OCaml to work under iOS and then developing the apps.


Schnapsen/66

Cassino

More recently we rewrote the apps (with much of the code unchanged) to run in the browser. These most recent versions are compiled to JavaScript using the Js_of_ocaml compiler, and run entirely in the browser. You can try them by clicking on the icons at the left. They play well enough to make an enjoyable opponent, and (at least to us) it’s pleasantly nostalgic to play the old iOS apps exactly as they were, in a rectangle exactly the size of the original iPhone.

Even more recently we rewrote the Slide24 example (described below) to run in the browser. Maybe there are OCaml programmers who’d like to see sources for a small and self-contained webapp written entirely in OCaml. You can run the app directly on the Slide24 page linked below, or you can download the sources and build it for yourself.

For many years this page offered resources for OCaml programming on iOS. The information is quite out of date by now, but we’ve gotten a few reports from OCaml-on-iOS folks that it’s still useful. So we’re continuing to offer it here for what it may be worth.

Example Apps

Right now we have one app, Slide24, that compiles to JavaScript and runs in the browser. We also have older descriptions of iOS apps that you could run on an iOS device or in the iOS simulator.

Each of these short descriptions contains a link to a page with details about the app.

Slide24 in the Browser

Slide24: Sliding Tile Puzzle Webapp

Slide24 is a small OCaml app that has GUI elements and animation. It plays the well known 5 × 5 sliding tile puzzle, and will solve it for you using a heuristic search. You can play it directly on the Slide24 page, or you can download sources and build it for yourself.

Slide24 (Shapiro Remix) is a variation of the Slide24 app intended for the younger set. It uses a milder form of shuffling to make the puzzle easier to solve. You can play it on the Slide24 (Shapiro Remix) page, or you can download the same Slide24 sources from the Slide24 page and build it for yourself.

Apps Packaged for iOS Devices

These apps were packaged to run on iOS devices. You could download the sources and build them with Xcode. However that was many years ago now. They could almost certainly be resurrected using a suitable OCaml-to-iOS compiler.

Portland: Which Way Is Up?

Portland is a very simple iOS app that shows which side of the iOS device is facing up. The name is a combination of portrait and landscape.

Slide24: Sliding Tile Puzzle

The Slide24 page describes the webapp version of Slide24. A description of the final iOS version can be found in the OCaml Programming Archives.

IcosaBlue: OpenGL ES Icosahedron

IcosaBlue uses LablGLES to display a rotating blue icosahedron. This app is also packaged for the simulator.

Apps Packaged for iOS Simulator

These apps were packaged to run in the iOS Simulator, and could be built with an OCaml compiler that generated 32-bit Intel code and linked to the iOS Simulator libraries.

Gamut: Color Browser

Gamut shows a changing display in all the possible colors, depending on where you touch the screen.

Voronoi: Cells of Influence

Voronoi displays cool pictures based on colored Voronoi diagrams that you can modify dynamically through the touch interface.

IcosaBlue: OpenGL ES Icosahedron

IcosaBlue uses LablGLES to display a rotating blue icosahedron. This app is also packaged for iOS devices.

Compilers and Libraries

OCaml on iOS

For many years we maintained a set of patches to change the OCaml compiler into an iOS cross compiler, one that compiles OCaml code to run as a native app on iOS devices. Subsequently, there was some work to improve these patches and integrate them into the official INRIA release of OCaml. As far as we know this work was never completed. But we’ll still keep our fingers crossed, as it would be excellent.

The proposed changes were integrated into a branch of the official OCaml GitHub repository. We checked out the branch and built versions of the OCamliOS compiler for 32-bit and 64-bit iOS. You can download the old prebuilt compilers here:

These were builds of OCaml 4.02.3 that run under OS X and generate code to run under iOS 7.0 and later (tested under iOS 9.2).

If you want to build the compilers yourself, you can read the instructions for building from source.

OCaml on iOS Simulator

We also modified OCaml 4.02.3 into an iOS Simulator cross compiler—it compiled OCaml to run as an app in the iOS Simulator available from Apple. This is a good way to experiment with iOS OCaml programming—you don’t need a device, and don’t need to register with Apple as an iOS developer. And it’s a convenient development environment even for registered iOS developers.

Support for iOS Simulator was also integrated in the iOS branch of the official OCaml GitHub repository. We built versions of the OCamliOSSim compiler for simulators of 32-bit and 64-bit iOS. You can download the old prebuilt compilers here:

If you want to build the iOS Simulator compilers yourself, you can read the instructions for building from source.

OpenGL ES from OCaml

We created an OCaml interface to OpenGL ES by adapting the LablGL interface created by Jacques Garrigue. We called it LablGLES for short. OpenGL ES is a reduced version of OpenGL, for doing graphics on small devices like the iPhone and iPad. Read the detailed instructions for building LablGLES.

Archives

Even more ancient versions of these binaries, patches, and sources are available in the OCaml Programming Archives.