From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA23889; Fri, 23 May 2003 00:56:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 AAA23873 for ; Fri, 23 May 2003 00:56:53 +0200 (MET DST) Received: from epexch01.qlogic.org ([63.170.40.3]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h4MMuqT19203 for ; Fri, 23 May 2003 00:56:52 +0200 (MET DST) Received: from epmailtmp.qlogic.org ([10.20.33.254]) by epexch01.qlogic.org with Microsoft SMTPSVC(5.0.2195.5329); Thu, 22 May 2003 17:54:59 -0500 Received: from [10.20.33.146] ([10.20.33.146]) by epmailtmp.qlogic.org with Microsoft SMTPSVC(5.0.2195.4905); Thu, 22 May 2003 17:54:58 -0500 Date: Thu, 22 May 2003 18:10:41 -0500 (CDT) From: Brian Hurt X-X-Sender: Reply-To: Brian Hurt To: hermanns cc: Subject: Re: [Caml-list] Why are arithmetic functions not polymorph? In-Reply-To: <147AB214-8CA5-11D7-B453-003065A2962C@gmx.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-OriginalArrivalTime: 22 May 2003 22:54:58.0847 (UTC) FILETIME=[2B8F0AF0:01C320B5] X-Spam: no; 0.00; qlogic:01 caml-list:01 stupid:01 equivalents:01 funtions:01 inference:01 foo:01 int-:01 oftentimes:01 compiler:01 ints:01 ocaml:01 overloading:01 int:01 arithmetic:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 23 May 2003, hermanns wrote: > Hello, > > I'm new to OCaml, so I hope my question is not to stupid. > > Can anybody explain to me why the arithmetic functions ('+', '-', ...) > are not polymorph > (in the sense that they have floating point equivalents '+.', '-.', > ...). > I don't understand this, because comparison funtions ('<', '>', ...) > are polymorph. > So, where is the problem with arithmetic functions? > Type inference is the short answer. Consider the function: let foo a b = a + b Without operator overloading, the type this function has is clear- + only operates on integers, so it's type is int->int->int. Were I to write: let foo a b = a +. b now the type is clearly float->float->float. The comparison operators call a generic- and comparitively expensive- comparison function. If you know that you are only going to be comparing (for example) ints, it's oftentimes faster to explicitly state the types involved, like: let foo (a: int) (b: int) = a < b This allows the compiler to replace the call to the expensive comparison function with a cheap inline integer comparison. Brian ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners