From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 46FC47FD02 for ; Sun, 3 May 2015 17:51:27 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of omeragacan@gmail.com) identity=pra; client-ip=209.85.212.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="omeragacan@gmail.com"; x-sender="omeragacan@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of omeragacan@gmail.com designates 209.85.212.181 as permitted sender) identity=mailfrom; client-ip=209.85.212.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="omeragacan@gmail.com"; x-sender="omeragacan@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f181.google.com) identity=helo; client-ip=209.85.212.181; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="omeragacan@gmail.com"; x-sender="postmaster@mail-wi0-f181.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BxAwB1Q0ZVm7XUVdFcgys0XAWDGLQIkDGGBAKBNwc7EQEBAQEBAQERAQEBAQEGCwsJIS6EIQEBAwESEQQZARsSCwEDAQsGBQsPAgkdAgIiAREBBQEKEgYTEhCHdAEDCQgNpVI+MYs5gWuCdogaChknAwpWhEgBAQEBAQEEAQEBARgBBQ6BE4oYhQUHgmiBRQWFPAqQWIZBgSQ9kGuCCBIjgQwJhDMiMYJFAQEB X-IPAS-Result: A0BxAwB1Q0ZVm7XUVdFcgys0XAWDGLQIkDGGBAKBNwc7EQEBAQEBAQERAQEBAQEGCwsJIS6EIQEBAwESEQQZARsSCwEDAQsGBQsPAgkdAgIiAREBBQEKEgYTEhCHdAEDCQgNpVI+MYs5gWuCdogaChknAwpWhEgBAQEBAQEEAQEBARgBBQ6BE4oYhQUHgmiBRQWFPAqQWIZBgSQ9kGuCCBIjgQwJhDMiMYJFAQEB X-IronPort-AV: E=Sophos;i="5.13,361,1427752800"; d="scan'208";a="114355389" Received: from mail-wi0-f181.google.com ([209.85.212.181]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 May 2015 17:51:26 +0200 Received: by widdi4 with SMTP id di4so97770456wid.0 for ; Sun, 03 May 2015 08:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=AEhaj8DHIVp5B0xmBdW4d1ITvPsl6ItMTQ6sp4vCXHM=; b=olO+1frjqsF5d1BhKgmHvU9+v4J6SkZeUi9iNsIs3zPoDCNgNJBIg2S0tcLWbmBYvl mRiqANNo7jrKL7lAyoJOEW+h3f5UTb9SnPGEjt34tpRZbVogItrYByD8duoafDtecojh dONNlXr05SYvrk8BCdG3/n6C8bFLaRAkPJcrSAYTswpf9+v9rU2Y053uiyBjSWw10iH0 0OXynBsIipVOr9Kf2e08QMvuafzxKcuvwfi+ttb/jy6TLCaHZWO5xjmwud1GgwS7jlb7 ZswN5slKwfvGGk+OOEIjditLbPS+sjV4rD4jIH1Q46ZY3NjvpFzeZoB+kGLZ3Keb2Amd ndhQ== X-Received: by 10.180.91.76 with SMTP id cc12mr12891451wib.67.1430668286094; Sun, 03 May 2015 08:51:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.187.212 with HTTP; Sun, 3 May 2015 08:50:45 -0700 (PDT) In-Reply-To: <1430666669.231526.262065573.6E243323@webmail.messagingengine.com> References: <20150501112114.1C8DFC382A@www1.g3.pair.com> <1430496980.1158661.261513285.08E1920C@webmail.messagingengine.com> <1430498707.1164081.261525093.47AD6B00@webmail.messagingengine.com> <5545384D.40803@mcmaster.ca> <554587C0.1070500@mcmaster.ca> <1430666669.231526.262065573.6E243323@webmail.messagingengine.com> From: =?UTF-8?Q?=C3=96mer_Sinan_A=C4=9Facan?= Date: Sun, 3 May 2015 11:50:45 -0400 Message-ID: To: Leo White Cc: OCaml Mailing List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Problems with printing MetaOCaml generated code > Personally, I think it is best to avoid this auto-magic and just do your > lifting by hand. The type-based auto-magic doesn't work with polymorphism, > whilst the value-based auto-magic is not parametric. Hm, I didn't know this was possible. I just tried and it seems to work really well: type stx = | A | B of stx | C of (stx * stx) let rec lift_stx (stx : stx) : stx code = match stx with | A -> .< A >. | B stx' -> .< B .~ (lift_stx stx') >. | C (stx1, stx2) -> .< C ( .~ (lift_stx stx1), .~ (lift_stx stx2) ) >. let stx = C (C (C (A, A), C (A, A)), C (C (A, A), C (A, A))) in print_code std_formatter .< .~ (lift_stx stx) >.; So it seems like I finally have a workaround now, thanks! The story of MetaOCaml code printing is still not completely clear to me, and this workaround means lots of boilerplace, but at least I have a workaround now and I can make progress. 2015-05-03 11:24 GMT-04:00 Leo White : >> I don't think this is true, as far as I can see MetaOCaml doesn't have open code >> values that are only runnable in environments that bind free variables in the >> code. >> >> # ..;; >> Error: Unbound value a >> # let a = 1 in ..;; >> - : int code = .<1>. >> >> In this example `..` didn't mean a code that is just the variable `a`, >> instead, `a` is lifted in code and code is now `.<1>.`. >> >> I think this automatic lifting is why MetaOCaml doesn't have explicit "lift" >> operation like MetaML does: variables bound in the environment automatically >> lifted, so no open code values are possible. > > It is true that MetaOCaml tries to auto-magically lift *some* things for you > (e.g. ints), as in this example. If type information is available, then for known > types it can produce a call to a function such as `Trx.lift_constant_int` to do the > lifting. For other types it will examine the value at run-time and attempt to lift it. > For example, if the value has a "string tag" then it can be represented by a string > literal. If this fails then it will fall back to using true CSP -- which can be run but > cannot be printed. > > Personally, I think it is best to avoid this auto-magic and just do your lifting by > hand. The type-based auto-magic doesn't work with polymorphism, whilst the > value-based auto-magic is not parametric. > > Regards, > > Leo > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs