From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 55C29BCAC for ; Fri, 13 May 2005 21:51:41 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j4DJpebM007098 for ; Fri, 13 May 2005 21:51:41 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA15053 for ; Fri, 13 May 2005 21:51:40 +0200 (MET DST) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j4DJpd6l006860 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Fri, 13 May 2005 21:51:40 +0200 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1DWgEr-0001yG-00 for ; Fri, 13 May 2005 20:54:25 +0100 Date: Fri, 13 May 2005 20:54:25 +0100 To: caml-list@inria.fr Subject: Very strange camlp4 error when using records Message-ID: <20050513195425.GA5994@furbychan.cocan.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i From: Richard Jones X-Miltered: at nez-perce with ID 4285054C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4285054B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocamlc:01 ocamlc:01 -pp:01 cmo:01 -pp:01 cmo:01 mlast:01 rec:01 iter:01 endline:01 toplevel:01 rec:01 ctyp:01 expr:01 ctyp:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: I have a strange case where the generated code looks completely correct - indeed, I can pretty-print the code, save it to a file, and compile it using ocamlc just fine. However when using the camlp4 preprocessor directly (ocamlc -pp "camlp4o ./pa_test2.cmo" ...), it fails to compile. $ ocamlc -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I +camlp4 -c pa_test2.ml $ ocamlc -pp "camlp4o ./pa_test2.cmo" -I +camlp4 -c test2.ml File "test2.ml", line 1, characters 11-18: Unbound value t.a $ camlp4o ./pa_test2.cmo pr_o.cmo test2.ml type t = { a : int } let rec t t = Array.iter print_endline [| string_of_int t.a |] (* generated code above compiles just fine in toplevel or ocamlc *) -- pa_test2.ml ----------------------------------------------- let rec generate loc name = function | <:ctyp< int >> -> <:expr< string_of_int $lid:name$ >> | <:ctyp< { $list:fields$ } >> -> let fields = List.map ( fun (loc, fname, mut, tdef) -> let name = name ^ "." ^ fname in generate loc name tdef ) fields in <:expr< Array.iter print_endline [| $list:fields$ |] >> | _ -> assert false DELETE_RULE Pcaml.str_item: "type"; LIST1 Pcaml.type_declaration SEP "and" END EXTEND GLOBAL: Pcaml.str_item; Pcaml.str_item: [[ "type"; tds = LIST1 Pcaml.type_declaration SEP "and" -> let typedefs = <:str_item< type $list:tds$ >> in let values = List.map ( fun ((loc, name), tparams, tdef, cl) -> let body = generate loc name tdef in <:patt< $lid:name$ >>, <:expr< fun $lid:name$ -> $body$ >> ) tds in <:str_item< declare $typedefs$; value rec $list:values$; end >> ]]; END -------------------------------------------------------------- -- test2.ml -------------------------------------------------- type t = { a : int } -------------------------------------------------------------- Ideas? Rich. -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com