Search code examples
ocamlcamlp4ocamlfind

How can I see the result Camlp4's preprocessing?


I'm using the Sexplib syntax extension in a file called module.ml, and I would like to see the code that is fed into the compiler after the Camlp4 preprocessing. Is there an easy way to do this using ocamlfind or do I have to invoke camlp4 directly and manually pass all the raw parameters?


Solution

  • This output

    $ camlp4o `ocamlfind query type_conv`/pa_type_conv.cma  `ocamlfind query sexplib`/pa_sexp_conv.cma /home/kakadu/.opam/4.01.0/lib/ocaml/camlp4/Camlp4Printers/Camlp4OCamlPrinter.cmo a.ml | pr -t -o4
    type t = (int * string)
    
    let _ = fun (_ : t) -> ()
    
    let __t_of_sexp__ =
      let _tp_loc = "a.ml.t"
      in
        function
        | Sexplib.Sexp.List ([ v1; v2 ]) ->
            let v1 = int_of_sexp v1 and v2 = string_of_sexp v2 in (v1, v2)
        | sexp -> Sexplib.Conv_error.tuple_of_size_n_expected _tp_loc 2 sexp
    
    let _ = __t_of_sexp__
    
    let t_of_sexp sexp =
      try __t_of_sexp__ sexp
      with
      | Sexplib.Conv_error.No_variant_match ((_tp_loc, sexp)) ->
          Sexplib.Conv_error.no_matching_variant_found _tp_loc sexp
    
    let _ = t_of_sexp
    
    let sexp_of_t (v1, v2) =
      let v1 = sexp_of_int v1
      and v2 = sexp_of_string v2
      in Sexplib.Sexp.List [ v1; v2 ]
    
    let _ = sexp_of_t
    

    For this source

    $ cat a.ml
    type t = int*string with sexp