我正在探索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发出:错误:未绑定模块打印机.Ocaml
我想是编译命令的问题,但我找不到在哪里实现 Printers.Ocaml。
谢谢你的帮助!_神父。
您正在尝试访问 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?
对不起,我的错误mudule Printers.Ocaml 不存在,Printers.OCaml(大写 C)存在。
我为此尝试了 2 天。
解决。