From: Jean-Christophe Filliatre <filliatr@csl.sri.com>
To: caml-list@inria.fr
Subject: wish: hash function for module Num
Date: Mon, 28 Feb 2000 17:08:12 -0800 (PST) [thread overview]
Message-ID: <14523.7164.321282.875777@cylinder.csl.sri.com> (raw)
[ francais ci-dessous ]
It would be nice if the module Num would provide a hash function for
type num, with the expected property:
eq_num n m => hash_num n = hash_num m
The generic hash function cannot be used, since equal nums may have
different representations, on which the generic hash function will
return different value (even with normalization after each
computation):
======================================================================
# open Num;;
# let _ = Arith_status.set_normalize_ratio true;;
- : unit = ()
# div_num (Int 1) (Int 1);;
- : Num.num = Ratio <abstr>
# Hashtbl.hash (div_num (Int 1) (Int 1));;
- : int = 504151169
# Hashtbl.hash (Int 1);;
- : int = 1
======================================================================
It is quite a mean trick, and makes the writing of a hash function
rather tedious, since you have to normalize the representation first.
More generally, I would expect the Num module to use a canonical
representation (as soon as we set_normalize_ratio).
== francais =================================================================
La fonction generique de hachage d'ocaml ne peut etre utilisee sur le
type Num.num, parce qu'un meme entier peut etre represente de
plusieurs manieres differentes, donnant des resultats differents (voir
exemple ci-dessus). Une fonction de hash fournie par le module Num
serait la bienvenue. Plus generalement, il serait souhaitable que le
module Num utilise une representation canonique pour chaque rationnel.
--
Jean-Christophe Filliatre
Computer Science Laboratory Phone (650) 859-5173
SRI International FAX (650) 859-2844
333 Ravenswood Ave. email filliatr@csl.sri.com
Menlo Park, CA 94025, USA web http://www.csl.sri.com/~filliatr
next reply other threads:[~2000-03-01 16:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-02-29 1:08 Jean-Christophe Filliatre [this message]
2000-03-01 17:04 ` Pierre Weis
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=14523.7164.321282.875777@cylinder.csl.sri.com \
--to=filliatr@csl.sri.com \
--cc=caml-list@inria.fr \
/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