Camlp4示例:未绑定模块Printers.Ocaml

时间:2012-11-23 08:47:05

标签: ocaml camlp4

我在this有用的博客文章之后探索Camlp4,但我有编译问题。 这是我的test.ml文件的代码:

open Camlp4.PreCast

let _loc = Loc.ghost in

let cons =
 let rec loop () =
   try
     match read_line () with
       | "" -> []
       | c -> c :: loop ()
   with End_of_file -> [] in
 loop () in
 Printers.Ocaml.print_implem
 <:str_item<
    type t =
    $Ast.TySum (_loc,
           Ast.tyOr_of_list
             (List.map
                 (fun c -> <:ctyp< $uid:c$ >>)
                 cons))$
    let to_string = function
    $Ast.mcOr_of_list
    (List.map
          (fun c -> <:match_case< $uid:c$ -> $`str:c$ >>)
        cons)$
    let of_string = function
    $let ors =
   Ast.mcOr_of_list
     (List.map
         (fun c -> <:match_case< $`str:c$ -> $uid:c$ >>)
         cons) in
    Ast.McOr(_loc,
           ors,
             <:match_case< _ -> invalid_arg "bad string" >>)$
>>

我正在使用此编译命令: ocamlc -pp camlp4of -I + camlp4 -o variant camlp4lib.cma test.ml 但ocamlc发出: 错误:未绑定模块Printers.Ocaml

我想这是编译命令的问题,但我找不到Printers.Ocaml的实现位置。

谢谢你的帮助! _ FR。

2 个答案:

答案 0 :(得分:3)

您正试图访问Camlp4.PreCast.Printers.OCaml.print_implemopen Camlp4.PreCast Printers.OCaml.print_implem后可访问;请注意OCamlOcaml的不同大小写; OCaml是标准的,应该在OCaml工具和文档中一致地使用(如果与编译器一起分发的某些库违反了约定,您可以提交一个小错误报告。)

PS:为了您的信息,下一版本的OCaml(4.01)可能会打印以下错误消息(使用开发版测试)

File "test.ml", line 13, characters 1-43:
Error: Unbound module Camlp4.PreCast.Printers.Ocaml
Did you mean OCaml?

答案 1 :(得分:0)

抱歉,我的错误 Printers.Ocaml模块不存在,Printers.OCaml(带有大写C)存在。

我在这上面试了两天。

解决。

相关问题