caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Miles Egan <miles@caddr.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] hash_variant anomalies
Date: Tue, 3 Jul 2001 09:42:10 +0200	[thread overview]
Message-ID: <20010703094210.A15237@pauillac.inria.fr> (raw)
In-Reply-To: <20010702180232.A51837@caddr.com>; from miles@caddr.com on Mon, Jul 02, 2001 at 06:02:32PM -0700

> [Question on tags for constant constructors and constant variant
> constructors]

> This test program seems to indicate otherwise:

No, no, it works as described in the manual, with two caveats:

1- The argument to hash_value() is the name of the variant constructor
without the leading ` (it's a syntactic marker, not part of the
constructor name), hence your test program should be:

> let _ =
>   calc_variant "YES";
>   print_variant YES;
>   calc_variant "NO";
>   print_variant NO;
>   calc_variant "MAYBE";
>   print_variant MAYBE;
>   calc_variant "YES";   <-- removed `
>   print_pvariant `YES;
>   calc_variant "NO";    <-- removed `
>   print_pvariant `NO;
>   calc_variant "MAYBE"; <-- removed `
>   print_pvariant `MAYBE  <-- there was a missing p and a missing `

With these corrections, I get:

variant 'YES' gives 8882703
variant is 1
variant 'NO' gives 34947
variant is 3
variant 'MAYBE' gives 36345617
variant is 5
variant 'YES' gives 8882703
variant is 8882703
variant 'NO' gives 34947
variant is 34947
variant 'MAYBE' gives 36345617
variant is 36345617

2- Owing to the Caml encoding of integers (integer N is represented by
the bit pattern for 2N+1), when the manual says that constant
constructors are numbered starting from 0, it really means that the
constant constructors are represented by the representation of 0, the
representation of 1, etc, that is, by 1, 3, etc.

In contrast, the return value of hash_value() is not a C integer but a
Caml value representing an already encoded integer.

> Also the manual states that both functions "hash_value" and
> "hash_variant" are used to compute the value of variants, but
> mlvalues.h seems to declare only "hash_variant".

Right, that's a typo in the manual: hash_variant() is the correct
function.

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  parent reply	other threads:[~2001-07-03  7:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-03  1:02 Miles Egan
2001-07-03  2:18 ` Chris Quinn
2001-07-03  7:42 ` Xavier Leroy [this message]
2001-07-03 15:15   ` Miles Egan
2001-07-04  0:19     ` Jacques Garrigue
2001-07-05  5:58       ` Miles Egan

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=20010703094210.A15237@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=miles@caddr.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).