From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id E6D4DBB9C for ; Thu, 17 Nov 2005 14:24:12 +0100 (CET) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAHDOB6p020112 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Thu, 17 Nov 2005 14:24:12 +0100 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1Eck4D-0005gA-00; Thu, 17 Nov 2005 13:44:45 +0000 Date: Thu, 17 Nov 2005 13:44:45 +0000 To: Chris Campbell Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Polymorphic variant to string? Message-ID: <20051117134445.GA19578@furbychan.cocan.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.28i From: Richard Jones X-Miltered: at concorde with ID 437C847B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 variants:01 camlp:01 variants:01 hash:01 endline:01 foo:01 baz:01 ocamlfind:01 ocamlc:01 -package:01 -linkpkg:01 notepad:01 123.:98 wrote:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Wed, Nov 16, 2005 at 06:44:34PM +0000, Chris Campbell wrote: > Is there a general method for converting polymorphic variants to > strings? The method using camlp4 assumes the source is compiled with > it, which is not the case. Basically I want to print a list of > variants if a unit tests fail, so we can see exactly the contents of > the list at that point. You might want to try Std.dump in extlib. It only prints out the hash, but you can precalculate those given a list of variant names. rich@oirase:/tmp$ cat test.ml print_endline (Std.dump [ `Foo; `Bar; `Baz 123.0 ]) rich@oirase:/tmp$ ocamlfind ocamlc -package extlib test.ml -linkpkg -o test rich@oirase:/tmp$ ./test [3505894; 3303859; (3303867, 123.)] Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com