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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 5D34ABC37 for ; Wed, 24 Feb 2010 17:42:23 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlNEAKflhEtQW+UMgWdsb2JhbACRKIlpFQEBFiQiiBi1BYRyBIVj X-IronPort-AV: E=Sophos;i="4.49,532,1262559600"; d="scan'208";a="57739974" Received: from lo.gmane.org ([80.91.229.12]) by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Feb 2010 17:42:22 +0100 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1NkKJY-00037t-7n for caml-list@inria.fr; Wed, 24 Feb 2010 17:42:20 +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 ; Wed, 24 Feb 2010 17:42:20 +0100 Received: from sylvain by ks300734.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 24 Feb 2010 17:42:20 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: OCaml/C variant representation Date: Wed, 24 Feb 2010 16:42:10 +0000 (UTC) Message-ID: References: <1bd843011002240726u6f0c3b87m7d58ab6415ea21ba@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 ocaml:01 val:01 val:01 hash:01 datatype:01 newty:01 foo:01 newty:01 camlprim:01 foo:01 hash:01 wrote:01 integer:01 Hello, On 24-02-2010, Jean Yang wrote: > Hello, > > I'm having some trouble with variant representation in the OCaml/C > interface. > > According to the reference I found ( > http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html), it seems like if > we have value v = variant VConstr(val), where val is some integer value, > should have Field(val, 0) == hash_variant("VConstr") and Int_val(Field(v, 0) >== val. I don't seem to be understanding this correctly, since I am getting > Int_val(Field(v, 0)) == val. > > I have the following datatype declaration in my OCaml: > type newty = VConstr of int | ... > In the C implementation of OCaml function foo : newty -> int, I have > something like this; > CAMLprim value foo (value v) { ... } > In the body of this function I am looking at the fields of val. Am I doing > something wrong here? > 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(...) Regards Sylvain Le Gall