[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-11-16 (21:29) |
From: | Jacques Garrigue <garrigue@m...> |
Subject: | Re: [Caml-list] Polymorphic variant to string? |
From: Chris Campbell <cyberdanx@gmail.com> > 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