Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
camlp4 and class introspection
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin_jambon@e...>
Subject: Re: [Caml-list] camlp4 and class introspection
On Mon, 11 Jun 2007, Joel Reymont wrote:

> On Jun 11, 2007, at 1:58 AM, Jacques GARRIGUE wrote:
>> Then you can use camlp4 to parse the .mli and generate the
>> registration code to be included in the .ml file.
> Right. I want to parse the class definition to extract instance variable 
> types and method signatures. Then I can use this information to create calls 
> to the Objective-C runtime.
> If there's an instance variable of type "float outlet", for example, then 
> I'll know to strip outlet from OCaml code and to tell ObjC that it's an 
> outlet. The whole purpose is to be able to define ObjC classes in OCaml while 
> automatically creating the glue and bridging code.

I see 2 main options:
- parse type definitions in standard OCaml syntax (what Jacques 
suggested): you can use an external 
preprocessor, the program can be compiled independently from camlp4, and 
you would discard type definitions that can't be converted to Objective-C. 
Another advantage is that you could use other similar preprocessors to 
generate code for other purposes.
- introduce a special kind of type definitions (like Yaron suggested), so 
that only these would generate Objective-C code. The big advantage is that 
you could add options. For example, if an OCaml type has 2 equivalents in 
Objective-C, you could add an annotation to choose which one to use.
It makes OCaml-like type definitions, which usually do not cover all 
possible type definitions and are not compatible with standard OCaml.