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 B7EFEBC37 for ; Thu, 25 Feb 2010 00:07:17 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAOM/hUtQRFuw/2dsb2JhbACbE3O8FoRyBI40 X-IronPort-AV: E=Sophos;i="4.49,534,1262559600"; d="scan'208";a="57756097" Received: from furbychan.cocan.org ([80.68.91.176]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 25 Feb 2010 00:07:17 +0100 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1NkQK3-0000AF-Lr; Wed, 24 Feb 2010 23:07:15 +0000 Date: Wed, 24 Feb 2010 23:07:15 +0000 To: Jean Yang Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] OCaml/C variant representation Message-ID: <20100224230715.GA32538@annexia.org> References: <1bd843011002240726u6f0c3b87m7d58ab6415ea21ba@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1bd843011002240726u6f0c3b87m7d58ab6415ea21ba@mail.gmail.com> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Spam: no; 0.00; ocaml:01 val:01 runtime:01 ocaml:01 topfind:01 findlib:01 camlp:01 camlp:01 syntax:01 syntax:01 topfind:01 usr:01 lib:01 usr:01 lib:01 On Wed, Feb 24, 2010 at 10:26:22AM -0500, Jean Yang wrote: > In the body of this function I am looking at the fields of val. Am I doing > something wrong here? As a general tip, use the extlib function Std.dump (or look at the source of Std.dump) to see how values are represented at runtime. For example: $ rlwrap ocaml Objective Caml version 3.11.2 # #use "topfind";; - : unit = () Findlib has been successfully loaded. Additional directives: #require "package";; to load a package #list;; to list the available packages #camlp4o;; to load camlp4 (standard syntax) #camlp4r;; to load camlp4 (revised syntax) #predicates "p,q,...";; to set these predicates Topfind.reset();; to force that packages will be reloaded #thread;; to enable threads - : unit = () # #require "extlib";; /usr/lib64/ocaml/extlib: added to search path /usr/lib64/ocaml/extlib/extLib.cma: loaded # type t = A | B | C of int | D of int ;; type t = A | B | C of int | D of int # Std.dump A ;; - : string = "0" # Stored as the OCaml int 0 # Std.dump B ;; - : string = "1" # Stored as the OCaml int 1 # Std.dump (C 42) ;; - : string = "(42)" # One-element block, tag 0 # Std.dump (D 42) ;; - : string = "Tag1 (42)" # One-element block, tag 1 # Std.dump ;; - : 'a -> string = # Std.dump `Foo ;; - : string = "3505894" # OCaml int, the hash of string "Foo" # Std.dump (`Foo 1) ;; - : string = "(3505894, 1)" # Two-element block, tag 0 # Std.dump (`Foo (1, 2)) ;; - : string = "(3505894, (1, 2))" # Two-elem block, second field is # another block. # Std.dump None ;; - : string = "0" # Std.dump (Some "foo") ;; - : string = "(\"foo\")" Rich. -- Richard Jones Red Hat