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 179B2BB9C for ; Wed, 16 Nov 2005 22:29:32 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id jAGLTRAu019667 for ; Wed, 16 Nov 2005 22:29:31 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id jAGLTMZb025889; Thu, 17 Nov 2005 06:29:23 +0900 (JST) Date: Thu, 17 Nov 2005 06:29:19 +0900 (JST) Message-Id: <20051117.062919.07648494.garrigue@math.nagoya-u.ac.jp> To: cyberdanx@gmail.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Polymorphic variant to string? From: Jacques Garrigue In-Reply-To: References: X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 437BA4B7.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 btype:01 hash:01 polymorphic:01 polymorphic:01 typing:01 probability:01 strings:01 argument:01 jacques:01 jacques: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 From: Chris Campbell > 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. The internal representation of a polymorphic variant tag is a hash by a given function (you can find it in typing/btype.ml) So, if you have the list of all possible variant tags, and their hash values, you just have to do a reverse lookup. Note that in theory, you need a list by type, as some independent types might map different tags to the same hash value, but in practice this should not be a problem: the probability of conflict is low enough. And of course this only apply to variant tags, not to argument values. Jacques Garrigue