From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4C1E5BC48 for ; Wed, 6 Apr 2005 19:01:52 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j36H1psn007675 for ; Wed, 6 Apr 2005 19:01:51 +0200 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 TAA12108 for ; Wed, 6 Apr 2005 19:01:51 +0200 (MET DST) Received: from hedwig1.umh.ac.be (hedwig2.umh.ac.be [193.190.193.73]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j36H1pZr023426 for ; Wed, 6 Apr 2005 19:01:51 +0200 Received: from poincare (mathwifi.swapping.umh.ac.be [10.102.100.18]) by hedwig1.umh.ac.be (8.13.1/8.13.1) with ESMTP id j36H1cgm1073360; Wed, 6 Apr 2005 19:01:55 +0200 Received: from localhost ([127.0.0.1] ident=trch) by poincare with esmtp (Exim 4.50) id 1DJDtR-0003wE-Qz; Wed, 06 Apr 2005 19:00:41 +0200 Date: Wed, 06 Apr 2005 19:00:26 +0200 (CEST) Message-Id: <20050406.190026.17170033.debian00@tiscali.be> To: eijiro_sumii@anet.ne.jp Cc: caml-list@inria.fr, sumii@saul.cis.upenn.edu Subject: Re: [Caml-list] ambitious proposal: polymorphic arithmetics From: Christophe TROESTLER In-Reply-To: <20050406.111505.68543084.eijiro_sumii@anet.ne.jp> References: <20050406.111505.68543084.eijiro_sumii@anet.ne.jp> Organization: Universite de Mons-Hainaut (http://math.umh.ac.be/an/) X-Spook: ANDVT Dateline Project Monarch M-14 Crypto AG underground Khaddafi basement BLU-97 A/B Ortega X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Operating-System: GNU/Linux (http://www.linux.org/) X-Mailer-URL: http://www.mew.org/ X-Mailer: Mew version 4.2 on Emacs 21.4 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.1 (www dot roaringpenguin dot com slash mimedefang) X-Miltered: at concorde with ID 425415FF.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 425415FF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 christophe:01 troestler:01 eijiro:01 sumii:01 eijiro:01 sumii:01 integers:01 imho:01 cvs:01 cvsweb:01 ocaml:01 functors:01 binary:01 statically:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.5 required=5.0 tests=FROM_ENDS_IN_NUMS autolearn=disabled version=3.0.2 X-Spam-Level: On Wed, 06 Apr 2005, Eijiro Sumii wrote: > Well, I am not anywhere as much known as you are in the FP community but let me jump in anyway! :) > So here it goes: why don't we have polymorphic +, -, etc. while we > have polymorphic =, <, etc.? [...] define +, -, etc. for as many > types as possible such as integers, floating-point numbers, and tuples? IMHO, the problem is not that much to have an handy set of polymorphic operators than to be able to _extend_ them. See for example http://cvs.alioth.debian.org/cgi-bin/cvsweb.cgi/shootout/bench/implicitode/implicitode.ocaml?rev=1.2&content-type=text/x-cvsweb-markup&cvsroot=shootout for a use of [open] and [let ... and ...] at the right places for the expressions to look "nice" (e.g. [a * b] instead of [M.( * ) a b]). In the mathematical world, this need occurs all the time. E.g. you define finite fields and want +, =,... to operate on those. You also want to define generic algorithms with those notions, e.g. power (as of now, functors would be used for this). The main difficulties currently are that (1) it is difficult to use [open] at the right places -- I have not checked whether the "openin" camlp4 extension can handle unary and binary operators -- and (2) mixing the operators in a single expression is impossible -- e.g. (a * b) * matrix. However, I would strongly like all this to be statically type checked -- no exceptions _please_. In fact, provided a suitable mechanism is found, I would like = to stop throwing exceptions. Personally I do not mid about +., *.,... even though admittedly they are odd at the beginning. But if 1 + 1.2 is going to throw an exception, this is far far worse (simple typing mistakes will now "crash" the program!!!). > P.S. I believe I'm not proposing anything as serious as Haskell type > classes. Imagine how val plus : [| int -> int -> int | float -> float -> float |] = will look once there are 10 types. This is going to be even worse if equality is to be _completely_ statically checked (as I desire). I only know superficially type classes, but (=) : Eq 'a => 'a -> 'a -> bool is much more readable than (=) : [| int -> int -> bool | float -> float -> bool | 'a list -> 'a list -> bool | ... |] Moreover and more importantly, they can be extended (e.g. add Num.num to the Eq class). Also, "subclassing" should be possible (e.g. Ordered 'a => Eq 'a). We are not allowing capitalized type names; this is a good opportunity to use them! In summary (since the opened the Pandora box), it would be nice if a solution would be found to this "problem" but, let's go for a general and useful one, not an had-oc one. :) Regards, ChriS --- P.S. Maybe GADTs provide an alternative solution for named functions but I believe not for binary operators.