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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 72AA3BC6B for ; Fri, 14 Dec 2007 17:16:39 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAMU7YkfAXQImh2dsb2JhbACQAwEBAQgKKZk/ X-IronPort-AV: E=Sophos;i="4.24,168,1196636400"; d="scan'208";a="20329481" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 14 Dec 2007 17:16:39 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id lBEGGVs8030674 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 14 Dec 2007 17:16:38 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAJc6YkdQW+UCh2dsb2JhbACQAwEBAQgKKZk+ X-IronPort-AV: E=Sophos;i="4.24,168,1196636400"; d="scan'208";a="5655717" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Dec 2007 17:16:34 +0100 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1J3DBE-0002TG-7Q for caml-list@inria.fr; Fri, 14 Dec 2007 16:14:28 +0000 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 ; Fri, 14 Dec 2007 16:14:28 +0000 Received: from li by ivr94-8-88-162-26-239.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 Dec 2007 16:14:28 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Zheng Li Subject: Re: "Ref" and copy of functions Date: Fri, 14 Dec 2007 17:12:00 +0100 Message-ID: <87zlwdi7cf.fsf@pps.jussieu.fr> References: <6cb897b30712130927m7df88e3axec56eacba4d47fdf@mail.gmail.com> <87d4t9k0uy.fsf@pps.jussieu.fr> <6cb897b30712140654v26a0ef96we6007c868d3d1829@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ivr94-8-88-162-26-239.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) Cancel-Lock: sha1:N2mvKPlSSngQ+cJrGZmn0btvlAU= Sender: news X-Miltered: at discorde with ID 4762AC5F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; mutation:01 ad-hoc:01 high-level:01 mutable:01 ocaml:01 existential:01 encode:01 pps:01 pps:01 functions:01 marshal:01 marshal:01 jussieu:01 jussieu:01 writes:01 Hi, "Pierre-Evariste Dagand" writes: > Yes, that's a CPS-way of doing things. I am aware of it and my first > implementation was in this style. > > The reasons why I decided to switch to Ref were that : > 1/ The implementation is much more "intuitive" (I don't have a CPS > pre-processor in my brain) > 2/ I thought I could get rid of my hack (Marshal/UnMarshal) easily > 3/ I used to think that I will be faster > > Point 1 is not a problem, Santa Claus might bring me this CPS > pre-processor in a few days. > > Point 2 seems to be wrong : being fast is nice but if it's for hitting > the wall, well... one should slow down. And for the moment, I haven't > found a clean solution and I'm not sure whether my hack is safe or > not. I guess you won't be able to find such a solution. In the Ref-based implementation, the result arrow type is stateful. You won't be able to _implicitly_ copy a state _inside_ the language, otherwise first-class continuation would already appear. A related issue appears on the "arr" function, if the argument "f" is itself stateful, even with a functional encoding like CPS won't help to copy the state inside. You can only solve this with a out-of-language solution such as Marshal or independent process evaluation . However, they also charge you cost. AFAIR, marshal (native code) has some cross-module safety problem. > So, remains point 3. That's why I have carried out an experience on my > initial Ref implementation, your Rectypes implementation and a CPS > implementation without rectypes (because rectypes frighten me). Since the corresponding mechanics in Ref and CPS are mutation and closure (de)construction, no wonder the former is faster. One ad-hoc solution, if you only have to provide high-level functional API to outside, is to make states explicit, like type ('a,'b) arrow = {mutable state: 'c; eval: 'c -> 'a -> 'b} This is not valid OCaml, since the 'c type is out of scope. You can either encode it with existential type (which also involve closure (de)construction, but I'm not sure about the cost). Or simply using Obj.t instead of 'c as far as you won't expose it, at least it won't be unsafer than Marshal and faster. -- Zheng Li http://www.pps.jussieu.fr/~li