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 (21:52)
From: Martin Jambon <martin_jambon@e...>
Subject: Re: [Caml-list] Camlp4: extending syntax of record definitions
On Tue, 19 Apr 2005, Markus Mottl wrote:

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

Besides from redistributing a modified or a program that patches and makes every entry public, I don't see any solution.

There would probably be problems for syntax extensions that are supposed
to work for both the regular and the revised syntax (I don't use the
revised syntax myself so it's only a problem if I want to please the
users of the revised syntax...).

Also, the minor grammar entries in happen to change from one
version of OCaml/Camlp4 to another, so it would be (even more) difficult
to maintain compatibility across various versions of OCaml if a syntax
extension had to rely on them.

I would love to know the point of view of the developers of Camlp4...

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

I see.

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

Thanks. I thought I should fill the gaps first (mainly English


Martin Jambon, PhD