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=AWL 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 62826BC69 for ; Sat, 12 May 2007 06:52:32 +0200 (CEST) Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4C4qVpo010861 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 12 May 2007 06:52:32 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay05.plus.net with esmtp (Exim) id 1Hmjap-0001jX-4O; Sat, 12 May 2007 05:52:31 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: skaller Subject: Re: [Caml-list] Custom operators in the revised syntax Date: Sat, 12 May 2007 05:47:05 +0100 User-Agent: KMail/1.9.5 References: <200705120348.50308.jon@ffconsultancy.com> <1178944803.14691.28.camel@rosella.wigram> In-Reply-To: <1178944803.14691.28.camel@rosella.wigram> Cc: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200705120547.06083.jon@ffconsultancy.com> X-Miltered: at concorde with ID 4645480F.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 0100,:01 inference:01 afaik:01 unify:01 variants:01 annotation:01 ocaml:01 run-time:01 compiler:01 run-time:01 fft:01 undecidable:01 vectors:01 vectors:01 On Saturday 12 May 2007 05:40, you wrote: > 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. Yes. > 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. AFAIK, you just change the unify to intersect sets of types. I assume the implementation of polymorphic variants already does this, so take that and make it enforce a single type contructor at function boundaries (maybe defaulting in some cases). If you "polymorphic variant" has more than one constructor then there is an ambiguity and you flag an error asking for a type annotation. > let f a b = a + b > > will pass type checking, The F# approach is to default + to int, to maintain compatibility with OCaml. > I know F# supports overloaded operators, but I have no idea > how it can work. .NET provides run-time type information so I assume the compiler specializes when types are static and resorts to run-time dispatch otherwise. I was certainly advised against using generics to implement a float/float32 FFT because they incur run-time tests for many simple arithmetic operations, killing performance. > 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. I hadn't thought of that. I just discovered that you cannot add vectors of vectors in F#, so it is probably 1st order only. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. The F#.NET Journal http://www.ffconsultancy.com/products/fsharp_journal/?e