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=none autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 2E779BB84 for ; Tue, 7 Oct 2008 16:35:40 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmMDAOsQ60jRVYC8lGdsb2JhbACBck2QZj4BAQEBCQkTEQOjIocGAQI X-IronPort-AV: E=Sophos;i="4.33,372,1220220000"; d="scan'208";a="15760602" Received: from fk-out-0910.google.com ([209.85.128.188]) by mail2-smtp-roc.national.inria.fr with ESMTP; 07 Oct 2008 16:35:39 +0200 Received: by fk-out-0910.google.com with SMTP id k31so2834886fkk.11 for ; Tue, 07 Oct 2008 07:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:organization:to:subject:date :user-agent:references:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:message-id:from; bh=knkAnYTznGpQF9PGVn7jMpBcTicT8hmssjWCjFrHDxA=; b=OnLqRssQvhf6CKHZfMzZdjtQn1KHnZTtdoKN6Cjn0LGXR/+T6rcIsqJO1tB2n7Ho7X RhxcmDxn0T4k2HxU7LrLulIRaZ5q06RNTL1m9M8ww1zUdqzamQKee5wQ3PZtR/ViwbYb rGAadTv2bDqYXuFmh6n/iQ2tCDoZCI4SW5eKo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=organization:to:subject:date:user-agent:references:in-reply-to :mime-version:content-type:content-transfer-encoding :content-disposition:message-id:from; b=ZR2w0PFGYchOR+6G1gm3FSifukMP00I+9z62KqBBVF/6q0t2HcxpY8mayODoWUrKHe g91feV0PRh2rbLntow3MiiRZx2gSfhgV6qN8jx7B2dpLi8NXHTK+ndP7xpTwE1C8ZYWK UlTN/fXZryIj78VqSpMT/WPfA5Pm4nrkUnAl0= Received: by 10.180.212.1 with SMTP id k1mr4920989bkg.58.1223390139588; Tue, 07 Oct 2008 07:35:39 -0700 (PDT) Received: from leper.local (host86-139-250-145.range86-139.btcentralplus.com [86.139.250.145]) by mx.google.com with ESMTPS id h1sm7921382nfh.19.2008.10.07.07.35.38 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 07 Oct 2008 07:35:38 -0700 (PDT) Organization: Flying Frog Consultancy Ltd. To: "Nicolas Pouillard" , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Metaprogramming features Date: Tue, 7 Oct 2008 16:36:43 +0100 User-Agent: KMail/1.9.9 References: <884069.59268.qm@web54601.mail.re2.yahoo.com> <200810070117.13329.jon@ffconsultancy.com> <1223383737-sup-3904@ausone.local> In-Reply-To: <1223383737-sup-3904@ausone.local> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200810071636.43288.jon@ffconsultancy.com> From: Jon Harrop X-Spam: no; 0.00; discrepancy:01 printf:01 printf:01 metaocaml:01 metaocaml:01 ocaml:01 faithful:98 frog:98 unbound:01 closures:01 wrote:01 caml-list:01 formulation:01 expression:02 defined:02 On Tuesday 07 October 2008 13:49:29 you wrote: > Excerpts from jonathandeanharrop's message of Tue Oct 07 02:17:13 +0200 2008: > > Surely the discrepancy is because the translation should be: > > > > let npower7 = > > let e = printf "power\n"; npower 7 (fun () -> x) in > > (fun () -> fun x -> e ()) ();; > > Hum "unbound value x" :) Oh yeah. :-) I hadn't noticed that you can do: # .< fun x -> .~ .. >.;; - : ('a, 'b -> 'b) code = . x_1>. Which seems to be the source of my confusion. So "x" is bound inside the escaped code even though it was defined in the "fun x ->" of the bracketed code. You are not allowed to do: # .< fun x -> .~ x >.;; Wrong level: variable bound at level 1 and used at level 0 That means a faithful translation into closures must capture such bound variables which will, in turn, defer the expression that does the constructing: let e x = printf "power\n"; npower 7 (fun () -> x) and that now fails to incur side-effects at the same time as the MetaOCaml program. So the translation from MetaOCaml to OCaml is not obvious at all. This begs the question: could another formulation of MetaOCaml avoid these complications without losing expressiveness? -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e