Re: Why no macros in CAML Light ?

Michel Mauny (Michel.Mauny@inria.fr)
Wed, 15 Nov 1995 16:28:25 +0100 (MET)

Message-Id: <199511151528.QAA15714@pauillac.inria.fr>
Subject: Re: Why no macros in CAML Light ?
To: Pierre.Weis@inria.fr (Pierre Weis)
Date: Wed, 15 Nov 1995 16:28:25 +0100 (MET)
In-Reply-To: <199511150936.KAA08832@pauillac.inria.fr> from "Pierre Weis" at Nov 15, 95 10:36:47 am
From: Michel.Mauny@inria.fr (Michel Mauny)

> > I wonder why there is no macro facility in CAML.
>
> > it would be nice to have at least the equivalent of C macros.
>
> No problem with this feature: you just have to write an equivalent of the C
> preprocessor (for instance in Caml itself) and make it available to
> the community!

Even simpler: use the C preprocessor itself! (with the -P option)
I know, it is tractable only under Unix, and using Makefiles...

> > Perhaps, there are implementation problems related with the type system of
> > CAML, but I can't figure out what they could be.

> Finally, the problem of macros in Caml is still an active research
> area ``in the background'', since it is definitively very powerful and
> elegant (and completely safe in conjonction with the type system): I
> hope it will be incoporated into Caml someday. In these lines, Daniel
> de Rauglaudre and Michel Mauny have designed and implemented a
> prototype of a new Caml dialect (we call it Chamau) with a very
> powerful ``quotation'' facility, which provides a powerful macro
> facility, which is still reasonably compatible with separate compilation.

I would simply say `compatible', not `reasonably compatible'.

By the way, quotations are some concrete way of noting structures such
as abstract syntax trees. For example, writing <<p(x,q(z,t))>> instead of
the binary tree:

Node("p", Leaf "x", Node("q", Leaf "z", Leaf "t")).

Quotations are just implicit calls to (user-defined) parsers. They
provide some (controlled) syntax extension facility.

Back to the discussion, now.

Just to make it clear, macros and quotations aren't exactly the same
thing. Neither macros, nor quotations cause real separate compilation
problems. (Well, for macros, it depends on the design.)

Both of them are compile-time evaluation (a function call for
quotations -- the function being known by the compiler --, and
arbitrary evaluations for macros). Both of them simply need some good
properties from the compiler.

On the other hand, macros, if implemented with an `eval' function,
need some form of dynamic typechecking. (To make sure that a
macro-evaluation -- that is, an arbitrary expression being evaluated
at compile-time -- returns a piece of program, expression or pattern
or..., according to the occurrence of the macro call in the source.)

For implementing syntax extensions, macros are just the most powerful
tool. That may be too much. Quotations are more restrictive, and more
reasonable as a syntax extension tool (in the sense that one can make
sure, in the design of the quotation mechanism, that there won't be no
dynamic type-checking).

The ultimate solution for syntax extensions, to my opinion, is to have
an extensible syntax. The only problem for that, is that the Yacc
technique isn't powerful enough.

About quotations, interested people may have a look at:

@InProceedings{Mauny-de-Rauglaudre94a,
author = "Michel Mauny and Daniel de Rauglaudre",
title = "A complete and realistic implementation of
quotations for {ML}",
booktitle = "Record of the 1994 {ACM-SIGPLAN} Workshop on
{ML} and its Applications",
page = "70--78",
month = jun,
year = 1994
}

-- 
Michel