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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id C95CF7ED7A for ; Tue, 2 Oct 2012 09:22:10 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of philippe.veber@gmail.com) identity=pra; client-ip=209.85.220.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of philippe.veber@gmail.com designates 209.85.220.54 as permitted sender) identity=mailfrom; client-ip=209.85.220.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="philippe.veber@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pa0-f54.google.com) identity=helo; client-ip=209.85.220.54; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="philippe.veber@gmail.com"; x-sender="postmaster@mail-pa0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlACAL2ValDRVdw2lWdsb2JhbAArGqxUiR4BiGAIIwEBAQEJCwkJEimCIAEBAQMBEgITGQEbEgsBAwELBgULDQ0hIQEBEQEFAQoSBhMSEIdQAQMJBgssml0JA4wlgWyBCYU4ChknAwpZiHUBBQyKMWKGSwOSOIFcgVWBFYoLAoMqFimECQ X-IronPort-AV: E=Sophos;i="4.80,521,1344204000"; d="scan'208";a="157534110" Received: from mail-pa0-f54.google.com ([209.85.220.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 02 Oct 2012 09:22:09 +0200 Received: by padbi1 with SMTP id bi1so5648686pad.27 for ; Tue, 02 Oct 2012 00:22:07 -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=xqsxm8/9XZxiy+ISS0lntt6Nl9O3hy6NLAWHnMGjHgg=; b=HwF24xTUbNjncPUEWyELd/wdyo5y5ukrLu13EJgAE43fXFy8itZngJvaMFWA2n0onc tQKDVVhBFaEl9oS6cNsobXig2Toul3nyj/A9sybXBchzmIf02kAPKCE5+pc50JBng0Mh fD9ACVUu2mDK9S9lHCArsAqM3/+Ftsacdnp7Egjuls4DvyaqfsVY4N6iK2HNiSmYS+KE U0wgmh3WTRiqyi3993OU2ASKdc8F08REbcFj4hXCxr4coLVN5yaaeDBhboYOk0WKl0vs WGt8VTkis2bPlB0mhyPsEiUM8HdZ4CdMURsFhTm64NdaSEjE1145jIQChprXBoFAutLW AUdQ== Received: by 10.68.138.170 with SMTP id qr10mr2098353pbb.53.1349162527577; Tue, 02 Oct 2012 00:22:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.66.254.129 with HTTP; Tue, 2 Oct 2012 00:21:47 -0700 (PDT) In-Reply-To: <5149DC70-C455-4BA1-AE3F-8A8CC5B6111C@recoil.org> References: <5149DC70-C455-4BA1-AE3F-8A8CC5B6111C@recoil.org> From: Philippe Veber Date: Tue, 2 Oct 2012 09:21:47 +0200 Message-ID: To: Anil Madhavapeddy Cc: Jeremy Yallop , caml users Content-Type: multipart/alternative; boundary=047d7b15aa2f3355c004cb0e6164 X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] Strange camlp4 issue --047d7b15aa2f3355c004cb0e6164 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Dear Jeremy and Anil, the problem is exactly the one you describe. My syntax extension largely reuses the one in js_of_ocaml; at some place there was this twisted construct in pa_js.ml: let obj =3D <:expr< ($e$ : Js.t (< .. > as $obj_type$)) >> in When adapting this code I carelessly simplified it in something like <:expr< fun () -> let _ : $obj_type$ Rbase.compound =3D $lid:x$#compound in ... >> and indeed camlp4 permutes [$obj_type$] and [Rbase.compound] in the generated code. At this point, the raison d'=EAtre of the afore mentionned construct is clear: if I use it too, the generated code (with camlp4o) is correct. It now looks like: <:expr< fun () -> let (_ : Rbase.compound (< .. > as $obj_type$)) =3D $lid:x$#compound in ... >> The fun part (which makes sense, of course) is that even if written in the wrong order in the quotation, camlp4o sets it right in the generated code. Thank you both for your very effective help! Cheers, Philippe. 2012/10/2 Anil Madhavapeddy > Another reason it might be going wrong is that your quotations are > generating invalid ASTs. This can happen when using the original syntax > quotations (which are more ambiguous than the revised syntax). > > To get around this sort of problem, I tend to use the 'camlp4orf' variant, > which uses the original syntax as the host language, and revised syntax f= or > quotations. This will mean that you need to learn the revised syntax for > the sole goal of writing quotations, but it is actually quite pleasant to > use (and certainly more fun than staring at dumps of raw AST fragments). > > -anil > > On 1 Oct 2012, at 15:39, Jeremy Yallop wrote: > > > Dear Philippe, > > > > On 1 October 2012 17:21, Philippe Veber > wrote: > >> let _ =3D (a7818b19c#compound : Rbase.compound > 'abdf89974) > > > > This appears to be the line where things are going wrong. > > Rbase.compound 'abdf89974 is not a valid type in original (i.e. > > standard) OCaml syntax, but is valid in the revised syntax. It may be > > that you're using the wrong camlp4 executable somewhere along the > > line: for example, using quotations for revised syntax in your > > extension, but building the extension using an original-syntax based > > executable such as camlp4o. There's a handy guide to the various > > camlp4 executables on the wiki: > > > > > http://brion.inria.fr/gallium/index.php/Using_Camlp4#Camlp4_executables_f= unctionalities > > > > You're seeing different error-reporting behaviour depending on whether > > you redirect the file because camlp4 checks whether it's printing to a > > terminal when deciding whether to print textual or binary output by > > default: > > > > > http://caml.inria.fr/svn/ocaml/trunk/camlp4/Camlp4Printers/Camlp4AutoPrin= ter.ml > > > > Hope that helps a bit, > > > > Jeremy. > > > > -- > > 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 > > > > --047d7b15aa2f3355c004cb0e6164 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Dear Jeremy and Anil,

the problem is exactly the one you describe. M= y syntax extension largely reuses the one in js_of_ocaml; at some place the= re was this twisted construct in pa_js.ml:<= br>
let obj =3D <:expr= < ($e$ : Js.t (< .. > as $obj_type$)) >> in

When adapting this code I carelessly simplified it= in something like

<:expr< fun () = -> let _ : $obj_type$ Rbase.compound =3D $lid:x$#compound in
...
>>

an= d indeed camlp4 permutes [$obj_type$] and [Rbase.compound] in the generated= code. At this point, the raison d'=EAtre of the afore mentionned const= ruct is clear: if I use it too, the generated code (with camlp4o) is correc= t. It now looks like:

<:expr< fun () -> let (_ : Rbase.compound (< .. > as $ob= j_type$)) =3D $lid:x$#compound in
...
>>

The fun part (= which makes sense, of course) is that even if written in the wrong order in= the quotation, camlp4o sets it right in the generated code.

Thank you both for your very effective help!

Cheers,
=A0 Phil= ippe.

2012/10/2 Anil Madhavapeddy <anil@recoil.org>
=
Another reason it might be going wrong is that your quotations are
generating invalid ASTs. This can happen when using the original syntax
quotations (which are more ambiguous than the revised syntax).

To get around this sort of problem, I tend to use the 'camlp4orf' v= ariant,
which uses the original syntax as the host language, and revised syntax for=
quotations. =A0This will mean that you need to learn the revised syntax for=
the sole goal of writing quotations, but it is actually quite pleasant to use (and certainly more fun than staring at dumps of raw AST fragments).

-anil

On 1 Oct 2012, at 15:39, Jeremy Yallop <yallop@gmail.com> wrote:

> Dear Philippe,
>
> On 1 October 2012 17:21, Philippe Veber <philippe.veber@gmail.com> wrote:
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0let _ =3D (a7818b19c#compou= nd : Rbase.compound 'abdf89974)
>
> This appears to be the line where things are going wrong.
> Rbase.compound 'abdf89974 is not a valid type in original (i.e.
> standard) OCaml syntax, but is valid in the revised syntax. =A0It may = be
> that you're using the wrong camlp4 executable somewhere along the<= br> > line: for example, using quotations for revised syntax in your
> extension, but building the extension using an original-syntax based > executable such as camlp4o. =A0There's a handy guide to the variou= s
> camlp4 executables on the wiki:
>
> http://brion.inria.fr/galli= um/index.php/Using_Camlp4#Camlp4_executables_functionalities
>
> You're seeing different error-reporting behaviour depending on whe= ther
> you redirect the file because camlp4 checks whether it's printing = to a
> terminal when deciding whether to print textual or binary output by
> default:
>
> http://caml.inria.fr/svn/ocaml/trun= k/camlp4/Camlp4Printers/Camlp4AutoPrinter.ml
>
> Hope that helps a bit,
>
> Jeremy.
>
> --
> Caml-list mailing list. =A0Subscription 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
>


--047d7b15aa2f3355c004cb0e6164--