caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Strange camlp4 issue
@ 2012-10-01 16:21 Philippe Veber
  2012-10-01 22:39 ` Jeremy Yallop
  0 siblings, 1 reply; 4+ messages in thread
From: Philippe Veber @ 2012-10-01 16:21 UTC (permalink / raw)
  To: caml users

[-- Attachment #1: Type: text/plain, Size: 1124 bytes --]

Dear camlp4ers,

A syntax extension of my own fails or succeeds on a given file depending on
the output :

[gesundheit:~/fitdistrplus 18:11]$camlp4o ~/.opam/3.12.1/lib/R/R_syntax.cma
src/fitdistrplus.ml
open Batteries

open Rbase

[...]
          method scale =
            List.nth
              (R.floats_of_t
                 (let a7818b19c = r in
                  let _ () =
                    let _ = (a7818b19c#compound : Rbase.compound 'abdf89974)
                    in
                      fun (ab922d605 : 'abdf89974) ->
                        (ab922d605#estimate : 'a8ec34edb)
                  in (a7818b19c#component "estimate" : 'a8ec34edb)))
              1
          method location_sd = assert false
          method scale_sd = assert false
          method fitdistcens = fitdistcens
        end

  end


[gesundheit:~/fitdistrplus 18:11]$camlp4o ~/.opam/3.12.1/lib/R/R_syntax.cma
src/fitdistrplus.ml > rien.ml
File "src/fitdistrplus.ml", line 157, characters 47-48:
Failure: "invalid type"

I observe this behaviour with versions 3.12.1 and 4.00.0

Does it ring a bell to someone?

Cheers,
  Philippe.

[-- Attachment #2: Type: text/html, Size: 4173 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange camlp4 issue
  2012-10-01 16:21 [Caml-list] Strange camlp4 issue Philippe Veber
@ 2012-10-01 22:39 ` Jeremy Yallop
  2012-10-01 22:45   ` Anil Madhavapeddy
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Yallop @ 2012-10-01 22:39 UTC (permalink / raw)
  To: Philippe Veber; +Cc: caml users

Dear Philippe,

On 1 October 2012 17:21, Philippe Veber <philippe.veber@gmail.com> wrote:
>                     let _ = (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_functionalities

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/Camlp4AutoPrinter.ml

Hope that helps a bit,

Jeremy.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange camlp4 issue
  2012-10-01 22:39 ` Jeremy Yallop
@ 2012-10-01 22:45   ` Anil Madhavapeddy
  2012-10-02  7:21     ` Philippe Veber
  0 siblings, 1 reply; 4+ messages in thread
From: Anil Madhavapeddy @ 2012-10-01 22:45 UTC (permalink / raw)
  To: Jeremy Yallop; +Cc: Philippe Veber, caml users

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 for
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 <yallop@gmail.com> wrote:

> Dear Philippe,
> 
> On 1 October 2012 17:21, Philippe Veber <philippe.veber@gmail.com> wrote:
>>                    let _ = (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_functionalities
> 
> 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/Camlp4AutoPrinter.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
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Strange camlp4 issue
  2012-10-01 22:45   ` Anil Madhavapeddy
@ 2012-10-02  7:21     ` Philippe Veber
  0 siblings, 0 replies; 4+ messages in thread
From: Philippe Veber @ 2012-10-02  7:21 UTC (permalink / raw)
  To: Anil Madhavapeddy; +Cc: Jeremy Yallop, caml users

[-- Attachment #1: Type: text/plain, Size: 3203 bytes --]

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 = <: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 = $lid:x$#compound in
...
>>

and indeed camlp4 permutes [$obj_type$] and [Rbase.compound] in the
generated code. At this point, the raison d'être 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$)) =
$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 <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' variant,
> which uses the original syntax as the host language, and revised syntax for
> 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 <yallop@gmail.com> wrote:
>
> > Dear Philippe,
> >
> > On 1 October 2012 17:21, Philippe Veber <philippe.veber@gmail.com>
> wrote:
> >>                    let _ = (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_functionalities
> >
> > 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/Camlp4AutoPrinter.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
> >
>
>

[-- Attachment #2: Type: text/html, Size: 4764 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-10-02  7:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-01 16:21 [Caml-list] Strange camlp4 issue Philippe Veber
2012-10-01 22:39 ` Jeremy Yallop
2012-10-01 22:45   ` Anil Madhavapeddy
2012-10-02  7:21     ` Philippe Veber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).