[
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: | -- (:) |
| From: | Xavier Leroy <Xavier.Leroy@i...> |
| Subject: | Re: [Caml-list] hash_variant anomalies |
> [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