English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Accessing constructors (tags) from C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-11-23 (18:38)
From: Eric Cooper <ecc@c...>
Subject: Re: [Caml-list] Accessing constructors (tags) from C
On Sun, Nov 23, 2008 at 01:22:46PM -0500, Raj Bandyopadhyay wrote:
> I was wondering how to access constructors from C.

See http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html,
in particular, section 18.3.

> For example if I define a type
> type t = Null | Int of int
> and I want to create values of type t in C using the OCaml-C
> interface, how do I find the integers corresponding to constructors
> Null or Int?

This falls under the section "Concrete types", where it says:

    The constant constructors and the non-constant constructors for a
    given concrete type are numbered separately, starting from 0, in
    the order in which they appear in the concrete type declaration.

> I would like to do this for a large OCaml program with lots of
> different types etc.

That will get tedious and error-prone.  I'd look into using an
interface description language and stub compiler, like camlidl or

Eric Cooper             e c c @ c m u . e d u