caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Bardur Arantsson <list-caml-list@scientician.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Camlp4 with traditional syntax
Date: Mon, 21 Feb 2005 17:57:22 +0100	[thread overview]
Message-ID: <20050221165722.GB20112@scientician.net> (raw)
In-Reply-To: <20050221.162224.41631465.oandrieu@nerim.net>

On Mon, Feb 21, 2005 at 04:22:24PM +0100, Olivier Andrieu wrote:

>  > Bardur Arantsson [Mon, 21 Feb 2005]:
>  > On Mon, Feb 21, 2005 at 01:28:25PM +0100, Alex Baretta wrote:

>  > > Hendrik Tews wrote:
>  > > >Alex Baretta <alex@barettadeit.com> writes:

>  > > >   There is one more issue with Camlp4: it does not allow for quotations
>  > > >   to expand to generic syntactic elements. Often, I use quotations which
>  > > >   expand to module definitions. I had to implement my own quotation
>  > > >   expander, bypassing the limitations of Camlp4 to achieve this.

>  > > >I don't quite understand, what's wrong with 

>  > > >let me = <:module_expr< struct $ list of module def's $ end >>
>  > > >in
>  > > >  <:str_item< module $some_name$ = $me$ >> 

>  > > We use quotation expanders to embed completely different
>  > > languages, such as SQL, within Ocaml code. Specifically, the SQL
>  > > quotation expander compiles SQL code to an Ocaml module. CamlP4
>  > > signals an error because quotations are only meant to be used as
>  > > expressions or as patterns, IIRC.

>  > IIRC quotations can expand to arbitrary ASTs. Only the point of
>  > *use* (ie. substitution) determines which types of ASTs will be
>  > accepted.

> No, quotations can expand to only expressions or patterns. See the
> type of a quotation expander in quotation.mli :

>   type expander =
>   | ExStr of (bool -> string -> string)
>   | ExAst of ((string -> MLast.expr) * (string -> MLast.patt))

> As Alex mentionned, ocpp expands quotations everywhere (but only deals
> with string-expanding quotations, not the AST ones), so it can be used
> to generate structure items (module elements).

You're right. I got confused by the distinction between user-defined and
pre-defined quotation expanders.

>  > Of course, if you're generating things like module interfaces and
>  > implementations, you'll need to generate them side by side since
>  > there is no "combined module interface+implementation" AST node
>  > type.

> The camlp4 AST does have this kind of nodes, as Martin mentionned.
> You can use :

> # fun a b -> <:str_item< declare $a$ ; $b$ ; end >> ;;
> - : MLast.str_item -> MLast.str_item -> MLast.str_item = <fun>

> or :

> # fun l -> <:str_item< declare $list:l$ end >> ;;
> - : MLast.str_item list -> MLast.str_item = <fun>

Uh, yes, you use <str_item:<...> to generate module implementations, but 
when I looked last you couldn't use MLast.sig_item and MLast.str_item
interchangably, so for instance, you couldn't ask pr_(o|r) to
pretty-print a str_item as a module interface. Instead you had to also
generate a sig_item and pretty-print that. (For good reason, you don't
necessarily want to have everything inside the module visible from the
outside...). That's all I was referring to by generating them "side by
side".

-- 
Bardur Arantsson
<bardur@imada.sdu.dk>
<bardur@scientician.net>

- It might look like I'm standing motionless, but I'm actively
waiting for my problems to go away.
                                                      Scott Adams


  reply	other threads:[~2005-02-21 16:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-17 15:32 Immediate recursive functions Alex Baretta
2005-02-17 18:20 ` [Caml-list] " Marcin 'Qrczak' Kowalczyk
2005-02-17 19:00 ` Jason Hickey
2005-02-17 20:33   ` Alex Baretta
2005-02-17 19:18 ` Christian Szegedy
2005-02-17 20:36   ` Alex Baretta
2005-02-17 22:39   ` Camlp4 documentation (was: Immediate recursive functions) Martin Jambon
2005-02-17 23:30     ` [Caml-list] " Richard Jones
2005-02-17 23:51       ` Michael Walter
2005-02-18  0:51     ` Micha
2005-02-18  3:37       ` briand
2005-02-18  5:21     ` Oliver Bandel
2005-02-18  6:51     ` Johann Spies
2005-02-18  8:04     ` [Caml-list] Camlp4 documentation Alex Baretta
2005-02-18  8:54       ` Alex Cowie
2005-02-18 16:20         ` Camlp4 with traditional syntax (was: Camlp4 documentation) Hendrik Tews
2005-02-18 16:28           ` [Caml-list] " Alex Baretta
2005-02-18 22:36             ` Hendrik Tews
2005-02-21 12:28               ` Alex Baretta
2005-02-21 12:55                 ` Bardur Arantsson
2005-02-21 15:22                   ` [Caml-list] Camlp4 with traditional syntax Olivier Andrieu
2005-02-21 16:57                     ` Bardur Arantsson [this message]
2005-02-18 18:43           ` [Caml-list] Camlp4 with traditional syntax (was: Camlp4 documentation) Martin Jambon
2005-02-18 22:41             ` Hendrik Tews
2005-02-22 10:29           ` Oliver Bandel
2005-02-22 23:32             ` Richard Jones
2005-02-23  0:01             ` Martin Jambon
2005-02-24  0:47               ` Oliver Bandel
2005-02-24 15:24                 ` William D. Neumann
2005-02-18  8:14     ` [Caml-list] Camlp4 documentation (was: Immediate recursive functions) Robert M. Solovay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050221165722.GB20112@scientician.net \
    --to=list-caml-list@scientician.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).