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 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 1638CBC6B for ; Fri, 24 Aug 2007 22:36:02 +0200 (CEST) Received: from pih-relay06.plus.net (pih-relay06.plus.net [212.159.14.133]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7OKa13V003039 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 24 Aug 2007 22:36:01 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay06.plus.net with esmtp (Exim) id 1IOfsu-0004TJ-S4 for caml-list@yquem.inria.fr; Fri, 24 Aug 2007 21:36:01 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Question on polymorphic typing for curried functions Date: Fri, 24 Aug 2007 21:25:00 +0100 User-Agent: KMail/1.9.7 References: <46CF34DE.301@cs.umn.edu> In-Reply-To: <46CF34DE.301@cs.umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200708242125.00613.jon@ffconsultancy.com> X-Miltered: at discorde with ID 46CF4131.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; curried:01 curried:01 polymorphism:01 val:01 val:01 bool:01 bool:01 polymorphism:01 ocaml:01 ocaml:01 1.0:98 2.0:98 frog:98 polymorphic:01 polymorphic:01 On Friday 24 August 2007 20:43:26 Christopher Kauffman wrote: > I am looking for a bit of information on the behavior of curried functions > wrt polymorphic arguments. For instance, in the following example, using a > curried function seems to lose the nice polymorphism that I desire. > > # let genf f a b = f a b;; > val genf : ('a -> 'b -> 'c) -> 'a -> 'b -> 'c = > # let specf = genf (<);; > val specf : '_a -> '_a -> bool = > # specf 1 2;; > - : bool = true > # specf;; > - : int -> int -> bool = > > An alternative definition for the specific 'specf' maintains polymorphism > of its arguments. > > # let specf a b = genf (<) a b;; > val specf : 'a -> 'a -> bool = > # specf 1 2;; > - : bool = true > # specf 1.0 2.0;; > - : bool = true > # specf;; > - : 'a -> 'a -> bool = > > Is there a set of rules or guidelines that determine when argument types > are specialized versus staying polymorphic? Yes. If you partially apply then you get a monomorphic result: # genf (<);; - : '_a -> '_a -> bool = If you then wrap that in any kind of closure then it becomes polymorphic again: # (fun a -> genf (<));; - : 'a -> 'b -> 'b -> bool = -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. OCaml for Scientists http://www.ffconsultancy.com/products/ocaml_for_scientists/?e