caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Jean Yang <jeanyang@csail.mit.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml/C variant representation
Date: Wed, 24 Feb 2010 23:07:15 +0000	[thread overview]
Message-ID: <20100224230715.GA32538@annexia.org> (raw)
In-Reply-To: <1bd843011002240726u6f0c3b87m7d58ab6415ea21ba@mail.gmail.com>

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 = <fun>
# 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


      parent reply	other threads:[~2010-02-24 23:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-24 15:26 Jean Yang
2010-02-24 16:42 ` Sylvain Le Gall
2010-02-28 15:16   ` [Caml-list] " Jianzhou Zhao
2010-02-28 16:22     ` Sylvain Le Gall
2010-02-24 23:07 ` Richard Jones [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100224230715.GA32538@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=jeanyang@csail.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).