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 XAA19169 for caml-red; Wed, 5 Jul 2000 23:16:58 +0200 (MET DST) 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 JAA24084 for ; Tue, 4 Jul 2000 09:09:29 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e6479Rf01252 for ; Tue, 4 Jul 2000 09:09:28 +0200 (MET DST) Received: from localhost (sansho.kurims.kyoto-u.ac.jp [130.54.16.90]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id QAA05728; Tue, 4 Jul 2000 16:09:18 +0900 (JST) To: sumii@saul.cis.upenn.edu Cc: caml-list@inria.fr Subject: Re: polymorphic equality and overloading In-Reply-To: Your message of "Fri, 30 Jun 2000 13:51:05 -0400" <20000630135105Q.sumii@saul.cis.upenn.edu> References: <20000630135105Q.sumii@saul.cis.upenn.edu> Mime-Version: 1.0 X-Mailer: Mew version 1.93 on Emacs 20.5 / Mule 4.0 (HANANOEN) Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20000704160900Z.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 04 Jul 2000 16:09:00 +0900 From: Jacques Garrigue X-Dispatcher: imput version 980905(IM100) Sender: weis@pauillac.inria.fr > > Equality really is overloaded, but since overloading isn't easily > > integrated into ML style type systems, some other solution is chosen. > > So, I'm wondering why equality is overloaded in Caml, unlike addition > (+ for integers, +. for floats, ^ for strings, etc.) for example. Or, > why is equality automatically defined for tuples and datatypes, while > addition isn't? Is that just because it is often useful? The answer is in your sentence: how do you define addition on tuples ? Or even on strings: ^ is not addition but concatenation; fun s1 s2 -> string_of_float (float_of_string s1 +. float_of_string s2) will give you a very different result. The only form of overloading currently accepted in Caml is universal overloading, that is operations available at all types. Comparison is just "naturally" defined on almost anything, the only exceptions being function closures which have no identity, and C data when no custom operation is defined. There is some arbitrary part in this definition, but even so being able to compare values is useful anyway (Set and Map modules). I do not really see what would be the use of an underspecified addition on algebraic datatypes, for instance. If you want other candidates for universal overloading, print would be a better choice. Theoretically all values can be printed in a way or another, and there may be uses for that. However this requires much more runtime type information. Regards, --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG