Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Newbie question: OCaml equivalent of Haskell's show?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-07-06 (19:02)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Newbie question: OCaml equivalent of Haskell's show?
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
(  This can turn anything into
a string, and tries to produce something which looks similar to an
OCaml toplevel value.

Documentation for Std.dump:

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 ...)

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


Richard Jones
Red Hat