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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id DBD84BC37 for ; Sun, 28 Feb 2010 17:22:51 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aiw9ADMniktQW+UMgWdsb2JhbACRNIloFQEBFiQiiBuwEoR7BIVk X-IronPort-AV: E=Sophos;i="4.49,556,1262559600"; d="scan'208";a="45635004" Received: from lo.gmane.org ([80.91.229.12]) by mail2-smtp-roc.national.inria.fr with ESMTP; 28 Feb 2010 17:22:51 +0100 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Nllur-0006Sm-Qh for caml-list@inria.fr; Sun, 28 Feb 2010 17:22:49 +0100 Received: from ks300734.kimsufi.com ([91.121.65.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Feb 2010 17:22:49 +0100 Received: from sylvain by ks300734.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 28 Feb 2010 17:22:49 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: OCaml/C variant representation Date: Sun, 28 Feb 2010 16:22:36 +0000 (UTC) Message-ID: References: <1bd843011002240726u6f0c3b87m7d58ab6415ea21ba@mail.gmail.com> <9dfe358d1002280716t4b756138m476455f1e86e44be@mail.gmail.com> X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ks300734.kimsufi.com User-Agent: slrn/pre1.0.0-11 (Linux) X-Spam: no; 0.00; le-gall:01 ocaml:01 le-gall:01 hash:01 ocaml:01 bindings:01 val:01 zhao:98 wrote:01 wrote:01 upenn:01 constructor:01 int:01 int:01 variant:02 On 28-02-2010, Jianzhou Zhao wrote: > On Wed, Feb 24, 2010 at 11:42 AM, Sylvain Le Gall wrote: >> On 24-02-2010, Jean Yang wrote: >> Please have a look at: >> http://caml.inria.fr/mantis/view.php?id=4803 >> >> This section is misleading. You should use hash_variant for `VConstr. >> >> In your case VConstr of int will be Block with size = 1 and tag = 0; >> first non-constant constructor and first field contains Value_int(...) > > If I am creating an OCaml variant (string option) from C, say using 'alloc', > does it matter which tag I am using for 'some'? Can it be only tag 0? > I was looking at LLVM OCamling bindings, sometimes the 'some' is > also of 'tag 1', which confused me. I think it is an error, but since there is only one possibility in the case of Some, maybe it is not important (i.e. you can distingish between the two variant None | Some just looking at the fact there are block or not). > If my variant is A | B | C of int | D of int, does C have to start from tag 0? > and D must be 1? Similarly, does A have to be assigned into Val_int(0), > and B is from 1? Yes. At least this is what I understand from section "18.3.4 Concrete types" of the OCaml manual. As a matter of fact, I never had problems following this convention before. Regards, Sylvain Le Gall