From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA00032 for caml-redistribution; Wed, 1 Mar 2000 17:46:37 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA25367 for ; Tue, 29 Feb 2000 02:08:17 +0100 (MET) Received: from csla.csl.sri.com (csla.csl.sri.com [192.12.33.2]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id CAA17526 for ; Tue, 29 Feb 2000 02:08:15 +0100 (MET) Received: from cylinder.csl.sri.com (IDENT:filliatr@cylinder.csl.sri.com [130.107.15.112]) by csla.csl.sri.com (8.9.1/8.9.1) with ESMTP id RAA04342 for ; Mon, 28 Feb 2000 17:08:13 -0800 (PST) Received: (from filliatr@localhost) by cylinder.csl.sri.com (8.9.3/8.8.7) id RAA17897; Mon, 28 Feb 2000 17:08:12 -0800 X-Authentication-Warning: cylinder.csl.sri.com: filliatr set sender to filliatr@cylinder.csl.sri.com using -f From: Jean-Christophe Filliatre MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14523.7164.321282.875777@cylinder.csl.sri.com> Date: Mon, 28 Feb 2000 17:08:12 -0800 (PST) To: caml-list@inria.fr Subject: wish: hash function for module Num X-Mailer: VM 6.62 under Emacs 20.4.1 Reply-To: filliatr@csl.sri.com (Jean-Christophe Filliatre) Sender: weis [ 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 # 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