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 TAA31201; Sat, 14 Aug 2004 19:10:48 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 TAA30714 for ; Sat, 14 Aug 2004 19:10:47 +0200 (MET DST) Received: from smtp3.adl2.internode.on.net (smtp3.adl2.internode.on.net [203.16.214.203]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i7EHAiRM024498 for ; Sat, 14 Aug 2004 19:10:45 +0200 Received: from [192.168.1.200] (ppp197-3.lns1.syd2.internode.on.net [203.122.197.3]) by smtp3.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i7EHAfHY076680; Sun, 15 Aug 2004 02:40:42 +0930 (CST) Subject: Re: [Caml-list] Infix operators From: skaller Reply-To: skaller@users.sourceforge.net To: Erik de Castro Lopo Cc: caml-list In-Reply-To: <20040814225919.0bed9f65.ocaml-erikd@mega-nerd.com> References: <20040814225919.0bed9f65.ocaml-erikd@mega-nerd.com> Content-Type: text/plain Message-Id: <1092503440.29139.660.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 15 Aug 2004 03:10:40 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 411E4794.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 inference:01 citeseer:01 gcaml:01 generic:01 avoiding:01 inference:01 9660:01 glebe:01 overloading:01 overloading:01 int:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, 2004-08-14 at 22:59, Erik de Castro Lopo wrote: > Hi all, > > I've got a number of defined types for which I'd like to define > infix operators for addition, subtraction, multiplication etc. > > Unfortunately since each type needs is own infix operator I'm > running out of ideas unique operator versions for each type. > > Why is it not possible to do something like: > > let ( ++ ) (a:float) (b:float) = a +. b ;; > > let ( ++ ) (a:int) (b:int) = a + b ;; There reason, roughly, is that it is very hard to combine type inference with overloading. It can be done (there's a paper on Citeseer describing an algorithm). It isn't clear what the error message quality would be though. The GCaml solution Richard Jones mentions: # generic plus = | int -> int -> int => (+) | float -> float -> float => (+.) ;; When you use this: plus 1 1 plus 1.0 1.0 there is only a *single* plus function, with several explicitly given typings -- thus avoiding the problem of combining inference with overloading neatly. -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- 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