Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I interface OCaml with iPhone API?

I'd like to start developing applications for iPhone, but I'd really like to use OCaml rather than Objective-C. After some googling, it seems like this is definitely possible, but I haven't found any code snippets which actually compile.

Is it possible to write iPhone apps using OCaml? If so, could you provide a snippet demonstrating how to make calls into the Cocoa API from OCaml?

like image 222
Juliet Avatar asked Jul 07 '09 21:07

Juliet


2 Answers

We have instructions for building an OCaml-to-iOS cross compiler on our site. We started with the patches mentioned above, but we found they needed to be modified in several ways to run on a stock iPhone/iPad. We are selling an iPhone app named Cassino that is entirely written in OCaml (except for thin wrappers to Cocoa Touch). Wrappers for all of Cocoa Touch would be a big job, but wrappers for a single application aren't so bad. And coding in OCaml is very pleasant compared to ObjC.

We also just published full sources for a small OCaml iPhone app named Portland at our site. Read more at psellos.com.

like image 142
Jeffrey Scofield Avatar answered Oct 10 '22 04:10

Jeffrey Scofield


Out of the box, OCaml cannot be used to build IPhone apps. You would have to have OCaml output ARM code rather than x86 code. You would also have to build wrappers for all the IPhone API calls.

Still, these guys are going through the pain to try this.

http://web.yl.is.s.u-tokyo.ac.jp/~tosh/ocaml-on-iphone/

My humble recomendation is that you focus on using Obj-C for everything. If you really want an ML, use it only for the kernel or the interesting portion. I would find an *ML that code gens to something like C, and then use that result as a library to the app.

Good luck.

like image 27
drudru Avatar answered Oct 10 '22 04:10

drudru