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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 6A9B8BC37 for ; Sun, 28 Feb 2010 16:16:14 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvYBAEMXikvRVaC2mGdsb2JhbACPOIQHh1UIFQEBAgEICQwHEyKIG6JzQoNWIohVAQEDBYR2BIMXiQY X-IronPort-AV: E=Sophos;i="4.49,555,1262559600"; d="scan'208";a="45703520" Received: from mail-gy0-f182.google.com ([209.85.160.182]) by mail3-smtp-sop.national.inria.fr with ESMTP; 28 Feb 2010 16:16:13 +0100 Received: by gya1 with SMTP id 1so952216gya.27 for ; Sun, 28 Feb 2010 07:16:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=TKjppNNMDHkkb22R5DhcoBgfXyJ2LeAk50skVg5sjeY=; b=Iyq6NDX8kPs0jtKLK0Wbv3cLKhhJMwdzaaV7XMw6VeAncODXsjeT6tyEdWSGbR18SY Uk67jui2ax9SLA7sWwksXkbE2K3soRPmIMOi+qMTXboLj19sY0U0TtxEZqs1yiYktvJB ABFtKNHpqU6fjWyh3UKhVFMQpxIB28GcK4HEI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=sLYvJcH/o7nZcdGuVYCSHQv/Qbk3+ewXIeKXIsAvUkYCjer3WPWwfRqJZI4fbdy5mk 5fgV7FSNZ6WBioxaRe8plp/mT9H0ZkTGFQWaTb9EAVhXmdudTRam+Y45Qs+4/+gGut27 e5RABiEvuswPz7ovHnbkXqW4sOLEgNYR5wrDQ= MIME-Version: 1.0 Sender: jianzhou.zh@gmail.com Received: by 10.101.128.39 with SMTP id f39mr4228012ann.52.1267370172224; Sun, 28 Feb 2010 07:16:12 -0800 (PST) In-Reply-To: References: <1bd843011002240726u6f0c3b87m7d58ab6415ea21ba@mail.gmail.com> Date: Sun, 28 Feb 2010 10:16:12 -0500 X-Google-Sender-Auth: 8eb5026101c09b2e Message-ID: <9dfe358d1002280716t4b756138m476455f1e86e44be@mail.gmail.com> Subject: Re: [Caml-list] Re: OCaml/C variant representation From: Jianzhou Zhao To: Sylvain Le Gall Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; ocaml:01 le-gall:01 ocaml:01 val:01 val:01 hash:01 datatype:01 newty:01 foo:01 newty:01 camlprim:01 foo:01 hash:01 bindings:01 beginner's:01 On Wed, Feb 24, 2010 at 11:42 AM, Sylvain Le Gall wro= te: > Hello, > > On 24-02-2010, Jean Yang wrote: >> Hello, >> >> =A0 I'm having some trouble with variant representation in the OCaml/C >> interface. >> >> =A0 According to the reference I found ( >> http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html), it seems lik= e if >> we have value v =3D variant VConstr(val), where val is some integer valu= e, >> should have Field(val, 0) =3D=3D hash_variant("VConstr") and Int_val(Fie= ld(v, 0) >>=3D=3D val. =A0I don't seem to be understanding this correctly, since I a= m getting >> Int_val(Field(v, 0)) =3D=3D val. >> >> =A0 I have the following datatype declaration in my OCaml: >> type newty =3D VConstr of int | ... >> In the C implementation of OCaml function foo : newty -> int, I have >> something like this; >> =A0 CAMLprim value foo (value v) { =A0... } >> In the body of this function I am looking at the fields of val. =A0Am I = doing >> something wrong here? >> > > Please have a look at: > http://caml.inria.fr/mantis/view.php?id=3D4803 > > This section is misleading. You should use hash_variant for `VConstr. > > In your case VConstr of int will be Block with size =3D 1 and tag =3D 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. 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? Thanks. Zjz > > Regards > Sylvain Le Gall > > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >