Excerpts from Richard W.M. Jones's message of Fri Mar 21 16:06:40 +0100 2008: > I'm trying to translate Sylvain Le Gall's gettext module to use camlp4 > from ocaml 3.10.0. The module is a printer which folds over the AST > looking for certain types of function call by name. A simplified > version is shown below. > > This program is supposed to look for all instances of a function named > f applied to a string. > > I cannot for the life of me work out how to get this to compile. I've > tried about a dozen different variations of the module names, 'open', > 'include' etc. and got a dozen different errors. You where very close to something working... Essentially three errors: > ---------------------------------------------------------------------- > module Id = struct > let name = "pr_gettext" > let version = "$Id$" > end > > module Make (Syntax : Camlp4.Sig.Syntax) Here it's Camlp4.Sig.Camlp4Syntax otherwise types are abstract and you don't have access to constructors. > : Camlp4.Sig.Printer(Syntax.Ast).S = > struct > module Loc = Syntax.Loc > module Ast = Syntax.Ast > > class visitor = object > inherit Ast.fold as super > > val t = [] > method t = t > > method expr = function > | <:expr@loc< f $str:singular$ >> -> Here you bind loc but don't use it, however that's just a warning. > let t = str :: t in Here the variable is singular not str. > {< t = t >} > > | e -> super#expr e > end > > let print_interf ?input_file ?output_file _ = () > > let print_implem ?input_file ?output_file ast = > let visitor = (new visitor)#str_item in > let t = (visitor ast)#t in > List.iter prerr_endline t > end > > (* Register the new printer. *) > module M = Camlp4.Register.Printer(Id)(Make) And here it's Camlp4.Register.OCamlPrinter because Camlp4.Register.Printer is too abstract. I attach three working versions of it. To compile them I use ocamlbuild -tags camlp4of,use_camlp4 pr_gettext.cmo The first [1] is very closer to yours. However you don't really define a proper printer here prerr_endline, so if the goal is just to iterate over the AST [2] is a simpler version. But why make an effect while one can easily go one step further and produce an OCaml output that define the list of strings to be translated [3]. Cheers, [1]: pr_gettext.ml [2]: pr_gettext_simple.ml [3]: pr_gettext_simple2.ml -- Nicolas Pouillard aka Ertai