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 TAA02479; Fri, 29 Nov 2002 19:08:10 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA02557 for caml-list@pauillac.inria.fr; Fri, 29 Nov 2002 19:08:10 +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 SAA01229 for ; Fri, 29 Nov 2002 18:27:40 +0100 (MET) Received: from ep09.kernel.pl (ep09.kernel.pl [212.87.11.162]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gATHRd127569 for ; Fri, 29 Nov 2002 18:27:39 +0100 (MET) Received: (qmail 5280 invoked by uid 566); 29 Nov 2002 17:27:32 -0000 Date: Fri, 29 Nov 2002 18:26:16 +0100 From: Michal Moskal To: Nicolas Cannasse Cc: caml-list@inria.fr Subject: Re: [Caml-list] Understanding why Ocaml doesn't support operator overloading. Message-ID: <20021129172616.GC16911@roke.freak> References: <200211282202.44717.jhf@hex.no> <20021129162608.B27468@pauillac.inria.fr> <001c01c297bf$436b7a20$4600a8c0@warp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <001c01c297bf$436b7a20$4600a8c0@warp> User-Agent: Mutt/1.4i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, Nov 29, 2002 at 04:52:03PM -0000, Nicolas Cannasse wrote: > Of course the ML type system relies on type inference and need do choose the > "best available" type but what if we enrich the type system with an "OR" > operator ? Then if (+) is overloaded on floats, you'll get : > > f : int -> int OR float -> float > or something like a type constraint : f : 'a -> 'a where 'a in [int;float] > > This approach seems trivial to me, but I really can understand that this > require a lot of addins in the typing algorithms & theory. BTW, does one of > the upper approach has already been discussed ? any paper on it ? any > countersample that will make me feel stupid ? :) The problem is what *assembly code* should be generated for function f? Code to add 2 integers or code to add 2 floats? Hmm.. we'll have a problem then. Or maybe both? And choose versions of f based on type it is applied to? But then consider: let f x1 x2 ... xn = ((x1 + x1), (x2 + x2), ..., (xn + xn)) you need to generate 2^n versions of f. We're getting to ugly things like C++ templates here. There is third answer: generate code that checks if it's passed int or float. But this has very significant perfomance impact. -- : Michal Moskal ::::: malekith/at/pld-linux.org : GCS {C,UL}++++$ a? !tv : PLD Linux ::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h ------------------- 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