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 DAA19264; Tue, 10 Dec 2002 03:02:03 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id DAA17881 for ; Tue, 10 Dec 2002 03:02:01 +0100 (MET) Received: from conure.mail.pas.earthlink.net (conure.mail.pas.earthlink.net [207.217.120.54]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id gBA21w114856; Tue, 10 Dec 2002 03:01:59 +0100 (MET) Received: from 2cust43.tnt7.sdg1.da.uu.net ([67.243.234.43] helo=earthlink.net) by conure.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 18LZie-0000SG-00; Mon, 09 Dec 2002 18:01:56 -0800 Message-ID: <3DF54B05.6E72368@earthlink.net> Date: Mon, 09 Dec 2002 18:01:41 -0800 From: Ken Rose Reply-To: rose@acm.org X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.2-2 i686) X-Accept-Language: en MIME-Version: 1.0 To: Daniel de Rauglaudre CC: caml-list@inria.fr Subject: Re: [Caml-list] Camlp4: generating printers of types References: <20021009151317.J1703@verdot.inria.fr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Daniel de Rauglaudre wrote: > > Hi everybody, > > In Camlp4 tutorial (current version), I added a section explaining how > to make a syntax extension which, when loaded, automatically generates > printers of all your types: > > For example, if your input file contains: > > type colour = Red | Green | Blue > > this will be interpreted like this: > > type colour = Red | Green | Blue > let print_colour = > function > Red -> print_string "Red" > | Green -> print_string "Green" > | Blue -> print_string "Blue" I've been working on extending this to more general types, which I suppose would be easy for someone who's had some practice with camlp4. I'm running into 2 problems, and anticipating a third one. 1. Is there a clean way to handle (sum) types with constructors with multiple module qualifications? I hacked the example to deal with Foo.bar, but it doesn't seem to extend automatically to Foo.Bar.baz. As I understand it, I'd need a new pattern for each additional uid. 2. How are tuples represented in camlp4's syntax? This is so I can match them when analyzing a type. 3. This is the big one. When working on a type like: type t = int with the obvious extention to Daniel's code, the preprocessor produces type t = int let rec print_t = print_int Which the compiler rejects with "This kind of expression is not allowed as right-hand side of `let rec'" I haven't been able to figure out a way to sneak it past, either. What's going on here? Why can't I rename print_int? Thanks - ken ------------------- 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