From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A3F2EBC69 for ; Sat, 12 May 2007 06:40:12 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4C4eAEQ008888 for ; Sat, 12 May 2007 06:40:11 +0200 X-IronPort-AV: E=Sophos;i="4.14,525,1170595800"; d="scan'208";a="126498510" Received: from ppp8-148.lns1.syd7.internode.on.net (HELO [192.168.1.201]) ([59.167.8.148]) by ipmail01.adl2.internode.on.net with ESMTP; 12 May 2007 14:10:06 +0930 Subject: Re: [Caml-list] Custom operators in the revised syntax From: skaller To: Jon Harrop Cc: Nicolas Pouillard , caml-list@yquem.inria.fr In-Reply-To: <200705120348.50308.jon@ffconsultancy.com> References: <200705111537.32561.jon@ffconsultancy.com> <200705120348.50308.jon@ffconsultancy.com> Content-Type: text/plain Date: Sat, 12 May 2007 14:40:03 +1000 Message-Id: <1178944803.14691.28.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4645452A.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 0100,:01 inference:01 haskell:01 typeclass:01 inference:01 compiler:01 overloading:01 ocaml:01 undecidable:01 sourceforge:01 wrote:01 caml-list:01 algorithm:01 constraint:01 On Sat, 2007-05-12 at 03:48 +0100, Jon Harrop wrote: > Using, +, +., +| and +|| is better than add, add_float, add_vector, add_matrix > but allowing + to be used to all such types ('a -> 'a -> 'a) is much better > still. It isn't even that hard to add to the language. Oh? It changes the way type inference works. I have only seen one algorithm for this an it was extremely complicated. If you know a better way I'd sure like to know what it is. Of course, you can use the Haskell typeclass approach, where you make the signature predefined as: (+): 'a -> 'a -> 'a and then resolve to the specific type and thus specific function (or error) after the usual inference/checking phase, however this *does* require a extra code in the compiler, possibly a complete extra phase that has to be done before type information is erased, it introduces new errors: let f a b = a + b will pass type checking, then fail during instantiation, whereas at present the signature is inferred as f: int * int -> int I know F# supports overloaded operators, but I have no idea how it can work. Felix also allows both overloading AND typeclasses, but it works because it does not have type inference. The only way I can see to extend Ocaml without breaking it would require the introduction of a new kind of type, which would at least allow finite sets of ground types, for example: int \U int16 \U int32 \U float \U bigint \U matrix Felix actually has these things, they're not types but nouns of sugar used for constraints: 'a constraint 'a = int | 'a = int16 ... and this kind of constraint, unfortunately, doesn't propagate (i.e. the above isn't really a type). Propagating ground type sets is actually easy, but once you have higher orders it is probably undecidable. -- John Skaller Felix, successor to C++: http://felix.sf.net