caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: cyberdanx@gmail.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Polymorphic variant to string?
Date: Thu, 17 Nov 2005 06:29:19 +0900 (JST)	[thread overview]
Message-ID: <20051117.062919.07648494.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <c22844d10511161044v4fb3a4b6i@mail.gmail.com>

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


  reply	other threads:[~2005-11-16 21:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-16 18:44 Chris Campbell
2005-11-16 21:29 ` Jacques Garrigue [this message]
2005-11-17 13:44 ` [Caml-list] " Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051117.062919.07648494.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=cyberdanx@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).