From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id AB7FDBC37 for ; Fri, 12 Feb 2010 22:30:07 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj8BACdXdUsRlBBojWdsb2JhbACbARUBAQEBCQkKCREGH78YhFgEgxMa X-IronPort-AV: E=Sophos;i="4.49,463,1262559600"; d="scan'208";a="52672617" Received: from asmtpout029.mac.com ([17.148.16.104]) by mail1-smtp-roc.national.inria.fr with ESMTP; 12 Feb 2010 22:30:06 +0100 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; charset=us-ascii Received: from [192.168.0.74] ([97.113.251.78]) by asmtp029.mac.com (Sun Java(tm) System Messaging Server 6.3-8.01 (built Dec 16 2008; 32bit)) with ESMTPSA id <0KXQ009ADZPPBP00@asmtp029.mac.com> for caml-list@yquem.inria.fr; Fri, 12 Feb 2010 13:29:52 -0800 (PST) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=5.0.0-0908210000 definitions=main-1002120169 Subject: Re: Ocaml, Objective-c, and XCode From: dynasticon@mac.com Message-id: <23CE720B-8521-47EA-A503-7A45B06CF67E@mac.com> Date: Fri, 12 Feb 2010 13:29:48 -0800 Cc: dynasticon@mac.com To: caml-list@yquem.inria.fr X-Mailer: Apple Mail (2.1077) X-Spam: no; 0.00; ocaml:01 ocaml:01 subset:01 bindings:01 interfacing:01 interfacing:01 superset:01 mismatch:01 structs:01 non-trivial:01 xcode:98 cocoa:98 cocoa:98 xcode:98 expressive:01 Andrew Webb writes: > I have a few questions relating to using Ocaml with objective-c for > anyone who programs on a Mac. We've been working with OCaml/ObjC/Cocoa on the iPhone for a while. We also have a small subset working on the Mac and have built Mac apps with it. > I am aware that there aren't any real bindings between ocaml and > objective-c/cocoa, so I am investigating rolling my own. This is what we did. There was some work on an OCaml/Cocoa bridge, but it doesn't appear to be finished, and doesn't look like an active project. The home page is here: http://code.google.com/p/objective-c-caml-bridge > 1) Does anyone have experience in interfacing ocaml and objc? Is it > difficult? The things that make it easier than it could be are: (a) There is good documentation on interfacing OCaml and C, and ObjC is a clean superset of C. So the language tools all work together quite well. (b) The OO subsystem of OCaml is a pretty good match for the Cocoa design. With some work, you can use OCaml objects to represent Cocoa objects, and vice versa. The hard parts are: (a) Cocoa is a very large system, too large for a small number of people to build an interface by hand. A mechanical interface generator would be best, but is also a big project. (b) There's a mismatch between the ObjC reference counting and OCaml GC. For our work, we just add bits to our interface as we need them. Memory management issues are tricky but only need to be solved once in the lowest layer. We don't have any experience with the ObjC GC; this might make things a little trickier. One thing to note is that we like OCaml because it's very flexible and expressive. If you mechanically translate all Cocoa objects and structs into their obvious OCaml corollaries, you lose a lot of the advantage of using OCaml. For example, we map Cocoa NSPoint values into OCaml 2-tuples, not into OCaml records. And we often use OCaml lists (with the correct base type) to represent NSArray objects. Because of this, we don't think a direct mechanical translation of Cocoa into OCaml is going to work. But a mechanical translation with sufficient overrides probably would. > 2) Does anyone have a small example project that does mix these two > languages? I have looked at unison, but it is too big for me to get my > head around. I am thinking more on the scale of the ubiquitous > Currency Converter... I don't know of anything. > 3) Does anyone who is mixing these languages use Xcode to do so? If > so, what steps do you need to go through to set that up? To be honest, we don't currently use Xcode in any non-trivial way. We just use its built-in knowledge about packaging up applications. There was a project to integrate OCaml into Xcode, but again it doesn't look like an active project. The home page is here: http://maxao.free.fr/xcode-ocaml-plugin Jeff Scofield Seattle