From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA14616; Tue, 10 Dec 2002 18:38:21 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 SAA14961 for ; Tue, 10 Dec 2002 18:38:20 +0100 (MET) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gBAHcKX06671 for ; Tue, 10 Dec 2002 18:38:20 +0100 (MET) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id SAA05486 for caml-list@inria.fr; Tue, 10 Dec 2002 18:38:20 +0100 Date: Tue, 10 Dec 2002 18:38:19 +0100 From: Daniel de Rauglaudre To: caml-list@inria.fr Subject: Re: [Caml-list] Camlp4: generating printers of types Message-ID: <20021210183819.H4933@verdot.inria.fr> References: <20021009151317.J1703@verdot.inria.fr> <3DF54B05.6E72368@earthlink.net> <20021210132502.J31055@verdot.inria.fr> <3DF60943.B9E543AB@earthlink.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3DF60943.B9E543AB@earthlink.net>; from kenarose@earthlink.net on Tue, Dec 10, 2002 at 07:33:23AM -0800 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Tue, Dec 10, 2002 at 07:33:23AM -0800, Ken Rose wrote: > and so on into gen_print_type. Or do I not understand what $uid:x$ > does? If x is a string <:expr< $uid:x$ >> produces "the uppercase identifier named by the value of x". If x is "Foo", this produces the identifier Foo. Notice that it works even if x does not contain an uppercase identifier: OCaml with interpret it as a module name or as a constructor name (depending on its position), whatever its value. Sorry, for your Baz.Baz.t, you need your <:ctyp< $uid:m2$.$uid:m$.$lid:s$ >> The better is to use an iterator, or use the recursion to treat the general case. > > In Revised syntax, they are like in normal syntax, but the parentheses > > are compulsory. > > Here, I want to match > type t = int * int > within gen_one_print_fun, to produce a printer instead of "failwith...". In Normal syntax, you can write "int * int" but inside the predefined quotations of AST, you have to use the Revised syntax. See the chapter about it in the reference manual. You must write it <:ctyp< (int * int) >>. And if tl is a list of ctyp, you can obtain the type tuple of this list of types with: <:ctyp< ($list:tl$) >> See the chapter about AST quotations. > > This message of OCaml just means that there are syntactic restrictions > > of the "let rec". In this case, you should produce either a "let" without > > "rec" or, an eta extension: "let rec print_t x = print_int x". > > I'd suspected that, though I'm still curious as to why that's so. Damien Doligez answered you on that point; this is typing and therefore not the work of Camlp4. > Still, what I really want is a generally useful tool to produce these > useful functions, without having to spend too much time right now > learning camlp4. It's for my regular work, where I'm building a > compiler for a DSL. I don't understand camlp4 well enough to know how > to suppress the "rec", and I'm hoping to avoid learning, at least for a > while. It's a great tool, but I have only so much time. Well, if you don't have time to look at it, I can help. -- Daniel de RAUGLAUDRE http://cristal.inria.fr/~ddr/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners