我正在浏览Camlp4,关注this上一系列有用的博客文章,但我遇到了编译问题。这是我的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 camlp4lib.cma test.ml但ocamlc发出:错误:未绑定模块Printers.Ocaml
我猜是编译命令的问题,但我不知道Printers.Ocaml是在哪里实现的。
谢谢你的帮助!_ Fr.
发布于 2012-11-23 17:48:43
您正在尝试访问Camlp4.PreCast.Printers.OCaml.print_implem,它在您的open Camlp4.PreCast之后可以作为Printers.OCaml.print_implem访问;请注意OCaml和Ocaml的不同大小写;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?发布于 2012-11-23 17:48:29
抱歉,我的错误是mudule Printers.Ocaml不存在,Printers.OCaml (大写C)存在。
我已经试了两天了。
解决了。
https://stackoverflow.com/questions/13525580
复制相似问题