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 AE1BBBC69 for ; Sat, 12 May 2007 08:05:16 +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 l4C65GiJ023353 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sat, 12 May 2007 08:05:16 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay06.plus.net with esmtp (Exim) id 1HmkjD-00052L-7F; Sat, 12 May 2007 07:05:15 +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 06:59:49 +0100 User-Agent: KMail/1.9.5 References: <200705120547.06083.jon@ffconsultancy.com> <1178948713.14691.89.camel@rosella.wigram> In-Reply-To: <1178948713.14691.89.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: <200705120659.49753.jon@ffconsultancy.com> X-Miltered: at concorde with ID 4645591C.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; syntax:01 0100,:01 afaik:01 unify:01 unify:01 val:01 annotation:01 val:01 unification:01 variants:01 vectors:01 vectors:01 statically:01 statically:01 run-time:01 On Saturday 12 May 2007 06:45, you wrote: > On Sat, 2007-05-12 at 05:47 +0100, Jon Harrop wrote: > > > 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 have no idea how to unify in the presence of (undiscriminated) > setwise union of polymorphic types. It seems a little easier > if the types are restricted to a finite set of non-polymorphic > types. They are, aren't they? e.g. int or float. If you write: > let ipow3 x = let sqr x = x*x in x * sqr x;; val ipow3 : int -> int then F# gives the inner definition "sqr" a type like [int|float] as 'a -> 'a until it is resolved to int -> int. If you change the code with an outer annotation: > let ipow3 x : float = let sqr x = x*x in x * sqr x val ipow3 : float -> float then it still works because the inner type specializes to float -> float rather than defaulting to int -> int. The outer definition of "ipow3" then becomes float -> float. > If ANYONE knows an algorithm that can do unification with > sets of types, that is, with a union type, I'd sure like > to know it! Isn't this exactly what polymorphic variants do? > > 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. > > Hmm, that's a bit surprising if your explanation above is correct, > that is, if it resorts to dynamic typing if it can't resolve > statically. I don't think it resorts to dynamic typing. I think it just doesn't do static code explosion as C++ templates do. That isn't dynamic typing because the types are still checked statically. I believe the F# standard library also does some run-time type based optimizations, like using specialized routines for vectors and matrices of floats. Again, this isn't really dynamic typing because it does not introduce any run-time errors. So if you do: type 'a complex = {r: 'a; i: 'a} let zero_float = {r=0.; i=0.} let zero_float32 = {r=0.f; i=0.f} then it doesn't generate type specialized code for float and float32 (same as OCaml). When you do: List.map ((+) 1) OCaml does not use a version of List.map that is specialized for ints. That isn't to say that the .NET JIT won't do the specialization itself, but I believe it does not currently do that. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. The F#.NET Journal http://www.ffconsultancy.com/products/fsharp_journal/?e