caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Antony Courtney <antony.courtney@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Newbie question: OCaml equivalent of Haskell's show?
Date: Sun, 6 Jul 2008 20:02:03 +0100	[thread overview]
Message-ID: <20080706190203.GA16430@annexia.org> (raw)
In-Reply-To: <3be64c030807060833y155230a2gaeaf0e531827ddb3@mail.gmail.com>

On Sun, Jul 06, 2008 at 11:33:35AM -0400, Antony Courtney wrote:
> I'm an experienced Haskell hacker trying OCaml for the first time.
> 
> One thing I am desperately searching for but have been unable to find
> is some direct runtime access to the string representation of
> arbitrary OCaml values.

Note that OCaml doesn't carry very much information at runtime about
what is represented in a value.  However there are various generic
printers around.  Probably your best bet for a quick and dirty hack is
to use the 'Std.dump' function in extlib
(http://code.google.com/p/ocaml-extlib/).  This can turn anything into
a string, and tries to produce something which looks similar to an
OCaml toplevel value.

Documentation for Std.dump:
  http://ocaml-extlib.googlecode.com/svn/doc/apiref/Std.html

If you want to go further than this and have OCaml write a pretty-
printer for your types, then you'll want to look at one of the
following projects (and probably others ...)

  http://www.ocaml.info/home/ocaml_sources.html
  http://code.google.com/p/deriving/
  http://tools.assembla.com/tywith/wiki

Another alternative is to run your code in the OCaml toplevel.

Rich.

-- 
Richard Jones
Red Hat


  reply	other threads:[~2008-07-06 19:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-06 15:33 Antony Courtney
2008-07-06 19:02 ` Richard Jones [this message]
2008-07-07 19:08   ` [Caml-list] " Jeremy Yallop
2008-07-06 21:09 ` Jon Harrop

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=20080706190203.GA16430@annexia.org \
    --to=rich@annexia.org \
    --cc=antony.courtney@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /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).