From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 13D86BC48 for ; Wed, 6 Apr 2005 19:23:20 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j36HNJr2026345 for ; Wed, 6 Apr 2005 19:23:19 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA11372 for ; Wed, 6 Apr 2005 19:23:19 +0200 (MET DST) Received: from qrnik.knm.org.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j36HNHev010968 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 6 Apr 2005 19:23:18 +0200 Received: from qrczak by qrnik.knm.org.pl with local (Exim 3.36 #1) id 1DJEFF-0005rj-00 for caml-list@inria.fr; Wed, 06 Apr 2005 19:23:13 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] ambitious proposal: polymorphic arithmetics X-Face: OW>RV&gN+&b-aiNY|U)f=S%w+/rK!);f>/W9IXg})]&F>ht.1Up8@04+_!gOp(_/l_-+E^. 2\vI)1=D,%HWiq)r(M/V~dr^5T^KF/[w5YZ4<0Sus3+O>l3uA/&W_21m?.s,Po8{pb0@ References: <20050406.111505.68543084.eijiro_sumii@anet.ne.jp> From: "Marcin 'Qrczak' Kowalczyk" Mail-Followup-To: caml-list@inria.fr Date: Wed, 06 Apr 2005 19:23:13 +0200 In-Reply-To: <20050406.111505.68543084.eijiro_sumii@anet.ne.jp> (Eijiro Sumii's message of "Wed, 06 Apr 2005 11:15:05 -0400 (EDT)") Message-ID: <87psx7lszi.fsf@qrnik.zagroda> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: "Marcin 'Qrczak' Kowalczyk" X-Miltered: at nez-perce with ID 42541B07.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42541B05.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 eijiro:01 sumii:01 eijiro:01 sumii:01 bool:01 runtime:01 bool:01 ocaml:01 dispatching:01 writes:01 polymorphic:01 polymorphic:01 functions:01 anet:02 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.2 X-Spam-Level: Eijiro Sumii writes: > So here it goes: why don't we have polymorphic +, -, etc. while we > have polymorphic =, <, etc.? =, < have type 'a -> 'a -> bool, so they appear to be applicable to *all* types. It happens that their implementation doesn't need to distinguish different types which currently have the same representation, it just examines the representation at runtime. 0 < 1 uses the same code as false < true. (Modulo special code generated based on the static type when it's known, but in polymorphic functions it is not known, so this must be optional, can't be relied on.) + can't be treated in the same way, because it won't distinguish whether it's called as 1 + 1 or true + true. If it returns 2 in the former case, it would produce a nonsensical bool value in the latter case. OCaml doesn't have a mechanism for making +, - applicable to a limited set of types and for dispatching their implementation based on the type rather than on the physical representation. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/