From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA15754; Tue, 3 Jul 2001 09:42:13 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA15746 for ; Tue, 3 Jul 2001 09:42:12 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f637gAj08656; Tue, 3 Jul 2001 09:42:10 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA15744; Tue, 3 Jul 2001 09:42:10 +0200 (MET DST) Date: Tue, 3 Jul 2001 09:42:10 +0200 From: Xavier Leroy To: Miles Egan Cc: caml-list@inria.fr Subject: Re: [Caml-list] hash_variant anomalies Message-ID: <20010703094210.A15237@pauillac.inria.fr> References: <20010702180232.A51837@caddr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20010702180232.A51837@caddr.com>; from miles@caddr.com on Mon, Jul 02, 2001 at 06:02:32PM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > [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