0

我正在按照这个有用的系列博客文章探索 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 的实现位置。

谢谢您的帮助!_ 神父。

4

2 回答 2

3

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

PS:供您参考,OCaml(4.01)的下一个版本可能会打印以下错误消息(已使用开发版本测试)

File "test.ml", line 13, characters 1-43:
Error: Unbound module Camlp4.PreCast.Printers.Ocaml
Did you mean OCaml?
于 2012-11-23T09:48:42.607 回答
0

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

我为此尝试了 2 天。

解决了。

于 2012-11-23T09:48:29.437 回答