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
Camlp4: extending syntax of record definitions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-04-19 (15:13)
From: Markus Mottl <markus.mottl@g...>
Subject: Re: [Caml-list] Camlp4: extending syntax of record definitions
On 4/18/05, Martin Jambon <> wrote:
> My experience in that field tells me that the more you try to extend
> existing syntaxic constructs, the more difficult it is.
> You have to look at from the Camlp4 distribution first, and see if
> the rule corresponding to record definitions is public (belongs to
> a "GLOBAL" entry) or not.

I had already copied half of the grammar to add my extension, but then
I thought that this is insane. I couldn't believe that there is no
simpler way of doing that, but obviously there really isn't.

> If the entry that contains this rule is public, then you can delete the
> rule and rewrite it, and everything is fine.
> Otherwise, you have to improvise. Which is the case here: the type_kind
> entry is not visible from outside.

Right. I had to essentially copy everything from "type_declaration"
downwards, which is quite a lot.

> One reasonable solution, in general, if you have a limited time or budget,
> is to extend str_item (items of a module implementation) with
> a whole new syntax. Something like:

I don't think that this is necessary, because it's only the type
declaration I want to change, not the syntax for record expressions.
The user must call the validation functions manually on his values.

> You can look at this example (uncommented), which is very similar:

Thanks, that's a very nice tutorial on Camlp4. Maybe it could be added
to the documentation index for OCaml at INRIA?

Best regards,

Markus Mottl