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.3 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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 43C19BC6B for ; Sat, 23 Jun 2007 23:41:04 +0200 (CEST) Received: from smtp5-g19.free.fr (smtp5-g19.free.fr [212.27.42.35]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5NLf3sL014853 for ; Sat, 23 Jun 2007 23:41:04 +0200 Received: from [192.168.1.222] (vil93-4-82-227-140-227.fbx.proxad.net [82.227.140.227]) by smtp5-g19.free.fr (Postfix) with ESMTP id B0AF22B6; Sat, 23 Jun 2007 23:41:03 +0200 (CEST) Message-ID: <467D936C.5020501@philippewang.info> Date: Sat, 23 Jun 2007 23:41:00 +0200 From: Philippe Wang User-Agent: Thunderbird 1.5.0.12 (Macintosh/20070509) MIME-Version: 1.0 To: Till Varoquaux , ocaml ml Subject: Re: [Caml-list] How do I get polymorphic partial application? References: <9d3ec8300706231155p2429504ay6395ea0580756dc7@mail.gmail.com> In-Reply-To: <9d3ec8300706231155p2429504ay6395ea0580756dc7@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 467D936F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; expansions:01 expansions:01 val:01 cheers:01 checker:01 sig:01 val:01 struct:01 polymorphic:01 polymorphic:01 wrote:01 partial:01 partial:01 rec:01 rec:01 Till Varoquaux wrote: > Humm... I have a small issue here: I need to get the result of the > partial application of a polymorphic function. Since variable are > generalized in Let it is generally advised to use eta expansions, > (i.e transform to a total application). > sometimes eta expansions just won't do the trick, consider: > > let cntTag start= > let cnt=ref start in > fun v -> ((incr cnt;!cnt),v) > > the partial application is not fully polymorphic > > let tag1 = cntTag 1 > > has type > > val tag1 : '_a -> int * '_a = > > the eta expanded equivalent doesn't have the same semantic (it > actually seems even less useful): > > let tag1 x= cntTag 1 x > > Is there an elegant solution to that problem? > Cheers, > Till > Hi, I think you should not try to "hide" that ugly side effect... If you do something like let rec f a = incr x ; a and x = ref 42 and start s = x := s ;; then you don't need to ask yourself how to bypass the type checker... Still, you can hide things in a module... module X : sig val f : 'a -> int * 'a val start : int -> unit end = struct let rec f a = incr x ; !x, a and x = ref 42 and start s = x := s end (* include X *) (only Obj.magic can do exactly what you're asking for -- except the "elegant" part) -- Philippe Wang mail[at]philippewang.info