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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 09CD1BC37 for ; Wed, 24 Feb 2010 16:26:25 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuIBANfThEvRVd27kGdsb2JhbACPMItZCBUBAQEBCQkMBxMDH656QoRhIohUAQEDBYRtBIMWiQM X-IronPort-AV: E=Sophos;i="4.49,532,1262559600"; d="scan'208";a="53545667" Received: from mail-qy0-f187.google.com ([209.85.221.187]) by mail1-smtp-roc.national.inria.fr with ESMTP; 24 Feb 2010 16:26:24 +0100 Received: by qyk17 with SMTP id 17so404821qyk.11 for ; Wed, 24 Feb 2010 07:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=CfxvDDxavVDZvWzLSCowbYSHkSpmCJEe1AXqd/faUsY=; b=Ym8gVRe34FNp10SnTQhmJbQWuw/8zLH624g6CKeEccbnuCBqOJtv6+GyalaEZ8SC0a mDtj21fL6sDM5p/HQuDZ884cqWSxeHatJJEw86dvHn6GRFVf7VU8scZPE907LcVRHR2B EzTKbE8zuMwBjreXeb1AfWfO+DsdnF9yOozs8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=GqUGA30iAA1y+1KaVMHG6bF+O29qCZoaT9y3gK+7nVj5vrUQua+ouZMGVnuxi683Jm caGXR+k6w/aku5kB1vqXWTQu1nc6gZ9MK/nynE9Svq8xIOZGt58diF7/mJfMPvPQ+C3Z NhI13JmGUCZ/FPmoskss+PjML2Zxds0iHBGX4= MIME-Version: 1.0 Sender: jean.yang.writeme@gmail.com Received: by 10.229.189.79 with SMTP id dd15mr599234qcb.3.1267025182753; Wed, 24 Feb 2010 07:26:22 -0800 (PST) Date: Wed, 24 Feb 2010 10:26:22 -0500 X-Google-Sender-Auth: a068ec5b62a1d870 Message-ID: <1bd843011002240726u6f0c3b87m7d58ab6415ea21ba@mail.gmail.com> Subject: OCaml/C variant representation From: Jean Yang To: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=0016361e81aef0876104805a49a5 X-Spam: no; 0.00; ocaml:01 ocaml:01 val:01 val:01 hash:01 datatype:01 newty:01 foo:01 newty:01 camlprim:01 foo:01 hash:01 datatype:01 camlprim:01 integer:01 --0016361e81aef0876104805a49a5 Content-Type: text/plain; charset=ISO-8859-1 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? Thanks, Jean -- Jean Yang http://people.csail.mit.edu/jeanyang Save us! Think before you print. --0016361e81aef0876104805a49a5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

=A0 I'm having some trouble with variant representation i= n the OCaml/C interface.

=A0 According to the reference I found (http://c= aml.inria.fr/pub/docs/manual-ocaml/manual032.html), it seems like if we= have value v =3D variant VConstr(val), where val is some integer value, sh= ould have Field(val, 0) =3D=3D hash_variant("VConstr") and Int_va= l(Field(v, 0) =3D=3D val.=A0 I don't seem to be understanding this corr= ectly, since I am getting Int_val(Field(v, 0)) =3D=3D val.

=A0 I have the following datatype declaration in my OCaml:
type newt= y =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.=A0 Am I doi= ng something wrong here?

Thanks,
Jean

-- Jean Yang
http://peopl= e.csail.mit.edu/jeanyang
Save us! =A0Think before you print.
--0016361e81aef0876104805a49a5--