From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 00760BBAF for ; Sun, 6 Jul 2008 21:02:06 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AigIANOycEhQRFuw/2dsb2JhbACDJql1 X-IronPort-AV: E=Sophos;i="4.30,311,1212357600"; d="scan'208";a="14865077" Received: from furbychan.cocan.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 06 Jul 2008 21:02:06 +0200 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1KFZUp-0004Kx-Ns; Sun, 06 Jul 2008 20:02:03 +0100 Date: Sun, 6 Jul 2008 20:02:03 +0100 To: Antony Courtney Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Newbie question: OCaml equivalent of Haskell's show? Message-ID: <20080706190203.GA16430@annexia.org> References: <3be64c030807060833y155230a2gaeaf0e531827ddb3@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3be64c030807060833y155230a2gaeaf0e531827ddb3@mail.gmail.com> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Spam: no; 0.00; ocaml:01 haskell's:01 haskell:01 ocaml:01 runtime:01 runtime:01 toplevel:01 wiki:01 toplevel:01 wrote:01 caml-list:01 arbitrary:02 newbie:02 hacker:02 represented:02 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