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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to