From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 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 5DF5CBB84 for ; Sun, 23 Nov 2008 19:38:31 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhACANkxKUmAArkpe2dsb2JhbACBbZFvAQEWIgWvVIRkhHCCfA X-IronPort-AV: E=Sophos;i="4.33,654,1220220000"; d="scan'208";a="20279366" Received: from chokecherry.srv.cs.cmu.edu ([128.2.185.41]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 23 Nov 2008 19:38:30 +0100 Received: from stratocaster.home (pool-98-111-219-222.pitbpa.fios.verizon.net [98.111.219.222]) (authenticated bits=0) by chokecherry.srv.cs.cmu.edu (8.13.6/8.13.6) with ESMTP id mANIcSaR001322 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sun, 23 Nov 2008 13:38:28 -0500 (EST) Received: from ecc by stratocaster.home with local (Exim 4.69) (envelope-from ) id 1L4Jqm-0004Q9-98 for caml-list@yquem.inria.fr; Sun, 23 Nov 2008 13:38:28 -0500 Date: Sun, 23 Nov 2008 13:38:28 -0500 From: Eric Cooper To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Accessing constructors (tags) from C Message-ID: <20081123183828.GB16898@localhost> Mail-Followup-To: caml-list@yquem.inria.fr References: <49299F76.6090006@rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <49299F76.6090006@rice.edu> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: mimedefang-cmuscs on 128.2.185.41 X-Spam: no; 0.00; constructors:01 constructors:01 integers:01 ocaml:01 error-prone:01 stub:01 compiler:01 camlidl:01 23,:98 wrote:01 caml-list:01 int:01 int:01 define:02 caml:02 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 ocamlrpcgen. -- Eric Cooper e c c @ c m u . e d u