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 D2BEBBC69 for ; Sat, 12 May 2007 12:14:49 +0200 (CEST) Received: from pih-relay06.plus.net (pih-relay06.plus.net [212.159.14.133]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4CAEni1009042 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 12 May 2007 12:14:49 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay06.plus.net with esmtp (Exim) id 1Hmoci-0000k2-Qg; Sat, 12 May 2007 11:14:48 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: "Nicolas Pouillard" Subject: Re: [Caml-list] Custom operators in the revised syntax Date: Sat, 12 May 2007 11:09:22 +0100 User-Agent: KMail/1.9.5 References: <200705120348.50308.jon@ffconsultancy.com> In-Reply-To: Cc: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200705121109.23192.jon@ffconsultancy.com> X-Miltered: at concorde with ID 46459399.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 encountering:01 defaults:01 val:01 hash:01 statically:01 unify:01 ocaml:01 val:01 syntax:01 overload:01 non-trivial:01 overloading:01 overloading:01 inference:01 On Saturday 12 May 2007 10:49, you wrote: > What your system should do when encountering: > > let double x = x + x;; F# ossifies global definitions to defaults (if any) or type errors. In this case: val double : int -> int If the definition had been: let first a = a.[0];; then there is no default and it would ask for clarification as to the type of "a" (is it an array, hash table, vector etc.). > double 1;; Fine. > double 1.1;; > double (Vector.from_array [| 1.1; 2.2; 3.3 |]);; Both static type errors. This seems to work very well by minimizing confusion, maximizing performance (everything is resolved statically) and letting me write mathematical expressions concisely. If the definition of "double" is nested then its type is not ossified immediately but will unify to "int" at the application "double 1;;", so the next two calls are static type errors just as they are in OCaml. There are other problems, like do we generalize from: val ( * ) : 'a -> 'a -> 'a to: val ( * ) : 'a -> 'b -> 'c e.g. "scalar * vector -> vector"? You also have ambiguity with conventional syntax. Does "vector * vector" mean dot, cross or element-wise product? Lessons can be learned from languages like Matlab, where people often accidentally add a scalar to each element of a vector (so we know that would be a useful type error). Potentially, you could even overload "f x" to allow it to mean multiplication when "f" is a numeric and not a functional value. So the type could go through ['a -> 'b | int | float | ...]. I've written about 100k LOC of F# code now and I haven't had a single non-trivial type problem caused by overloading. So I'd definitely question the conventional view that overloading and inference do not sit well together. Worst case, the compiler asks for a type annotation... -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. The F#.NET Journal http://www.ffconsultancy.com/products/fsharp_journal/?e