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=1.0 required=5.0 tests=AWL,SPF_FAIL 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 AC585BC6B for ; Sun, 24 Jun 2007 00:06:51 +0200 (CEST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5NM6oZa018556 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Sun, 24 Jun 2007 00:06:51 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1I2Dkj-0005Ia-Cv for caml-list@inria.fr; Sun, 24 Jun 2007 00:06:45 +0200 Received: from ivr94-8-88-162-26-239.fbx.proxad.net ([88.162.26.239]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 24 Jun 2007 00:06:45 +0200 Received: from li by ivr94-8-88-162-26-239.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 24 Jun 2007 00:06:45 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Zheng Li Subject: Re: How do I get polymorphic partial application? Date: Sun, 24 Jun 2007 00:07:35 +0200 Message-ID: <871wg2mijc.fsf@pps.jussieu.fr> References: <9d3ec8300706231155p2429504ay6395ea0580756dc7@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: ivr94-8-88-162-26-239.fbx.proxad.net User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:zMbCJJ5jK47Yam9/51a2qw/knPc= Sender: news X-Miltered: at discorde with ID 467D997A.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; expansions:01 expansions:01 val:01 parametrized:01 polymorphic:01 polymorphic:01 partial:01 partial:01 writes:01 pps:01 pps:01 jussieu:01 jussieu:01 func:01 func:01 "Till Varoquaux" writes: > 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: Well, there are cases eta expansions won't help. somehow you must modify your code. > 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 = I suppose you still want to create different instance with parametrized counter. You can do it in this way: # type tag_func = {func: 'a. 'a -> int * 'a} ;; # let cnTag s = let r = ref s in {func = fun x -> incr r; !r, x} ;; (* either explicit use tag1.func here *) # let tag1 = cnTag 1 ;; # tag1.func 10;; - : int * int = (2, 10) # tag1.func "asdf";; - : int * string = (3, "asdf") (* or one extra step *) # let tag1 = cnTag 1 ;; # let tag1 x = tag1.func x ;; # tag1 10;; - : int * int = (2, 10) # tag1 "asdf";; - : int * string = (3, "asdf") HTH. -- Zheng Li http://www.pps.jussieu.fr/~li