Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Camlp4: generating printers of types
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-12-10 (15:33)
From: Ken Rose <kenarose@e...>
Subject: Re: [Caml-list] Camlp4: generating printers of types

I worded things badly enough that nobody understood what I was actually
after.  What I want is help extending your automatically generated
printing functions to handle all the types I actually use.

Daniel de Rauglaudre wrote:
> On Mon, Dec 09, 2002 at 06:01:41PM -0800, Ken Rose wrote:
> > 1. Is there a clean way to handle (sum) types with constructors with
> > multiple module qualifications?  I hacked the example to deal with
> >, 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.
> I don't understand that: in the type definition, there is no qualifications
> for the constructors.

This is for a type like:

type x = A of int * Foo.t * Bar.Baz.t
       | ...

Where I don't want to have to put in 
    | <:ctyp< $uid:m$.$lid:s$ >> -> <:expr< $uid:m$.$lid:fun_name s$ >>
    | <:ctyp< $uid:m2$.$uid:m$.$lid:s$ >> -> <:expr<
$uid:m2$.$uid:m$.$lid:fun_name s$ >>

and so on into gen_print_type.  Or do I not understand what $uid:x$

> > 2. How are tuples represented in camlp4's syntax?  This is so I can
> > match them when analyzing a type.
> 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...".

> > 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?
> 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. 
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.

Thanks for any help you're willing to give,

 - ken
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: