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 PAA05660 for caml-red; Mon, 18 Dec 2000 15:50:49 +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 PAA31699 for ; Sat, 16 Dec 2000 15:11:12 +0100 (MET) Received: from localhost.localdomain (kenny90.zip.com.au [61.8.18.218]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eBGEB8n08583 for ; Sat, 16 Dec 2000 15:11:09 +0100 (MET) Received: from ozemail.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id BAA10127; Sun, 17 Dec 2000 01:10:38 +1100 Message-ID: <3A3B77DE.162549AD@ozemail.com.au> Date: Sun, 17 Dec 2000 01:10:38 +1100 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Mattias Waldau CC: caml-list@inria.fr Subject: ROverloading References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: weis@pauillac.inria.fr Mattias Waldau wrote: > >> I would like to note that type inference (i.e. code without > >> annotations) helps a lot when developing programs: the annotation free > >> code is not only easier to write but also easier to maintain since it > >> is kind of ``auto-adaptative'' and resistant to reorganisations and > >> names modifications. > > If this were important, we shouldn't have different operators for * and *. > I had to change a program from integers to float recently, and it isn't fun > at all. Overloading is, perhaps unfortunately, more or less mandatory in the long run, perhaps not so much to support 'ad hoc polymorphism' as to relieve the programmer of learning lots of names for things. In Ocaml, learning + for int and +. for float isn't so bad. But add in ten other integer representations, and we're rapidly forced to resort to named prefix operators (i.e. function names). Unfortunately, overloading isn't quite so simple when you've also got type inference: let f a b = a + b in let x = f 1.0 2.0 in let y = f 1 2 in If we take 'f' to be monomorphic, then the second call is in error, because the overloaded + in the definition of 'f' doesn't determine it's type until x is calculated. Otherwise, 'f' could be taken to define an overloaded set of functions (somewhat like a C++ template) and the calculations of x and y would call different specialisations .. but this rapidly gets quite messy. Felix supports overloading, but it works more easily because functions must be explicitly typed. Nevertheless it is sometimes necessary to explicitly resolve an overload: function f(a:int):int { ..} function f(a:float):float { ..} val g = f of (int); // which f? because there is inference of val's and var's, and, even without that: function g(f:int->int):int { .. } function g(f:float->float):float { .. } .. g(f of (int)) .. //which g? depends on which f! -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net