[wg-camlp4] Pending issues
Hongbo Zhang
hongboz at seas.upenn.edu
Thu Feb 14 13:50:27 GMT 2013
On Thu, Feb 14, 2013 at 6:48 AM, Wojciech Meyer <wojciech.meyer at gmail.com>wrote:
> Another way of providing these simple asts would be to treat any
> flavor of variants uniformly and then in the end transform it back to
> what was expected (only if it's needed).
>
> (I don't know if that what wasn't originally proposed by Pierre).
>
> So regardless if it's a polymorphic variant, GADT, or plain data type,
> we would have one AST - the common denominator and what matters of
> these is usually the tag name and general signature. Once we have that
> we will match from that simple AST our type driven plugin that will
> generate JSON, XML, visitors. etc The idea is to have something that
> is good enough and reflects general structure to get rid of
> complicated parse tree or/and quotations on the LHS and/or factor out
> the common pattern matchers using some meta object.
>
> We could go even further and generate all the bolier plate pattern
> matchers via visitor pattern by default, of course it needs to be
> thought - but the idea is to not look at types at all - now it turns
> to be it's already a meta-meta programming.
>
> That's how ast works in Fan, constructor names are not associated with
type at
all.
So, suppose you have a function
sem_of_list, it works for all syntax categories, in Camlp4 you need to
write sem_of_list_ctyp, sem_of_list_expr,.....
Second, no dependency, in Fan, you can write tons of libraries for Fan
without depending on Fan, since Fan adopts polymorphic variants, you don't
have to fix its type in the first place. There is a nice application here:
reflection or runtime types generated by Fan. For each compilation unit,
for example, a.ml, Fan can inject a value in the module A, called
repr_of_a, which stores the ast as a runtime value(there is a subtle
difference here, it's a runtime value), which means you can program it in
vanilla ocaml without marshalling or demarshalling
Third, subtyping, you can pick a subset of the ast you want to process,
while reuse most of existing Fan's utilities. The contract is detected at
compile time.
> On Wed, Feb 13, 2013 at 5:56 PM, Leo White <lpw25 at cam.ac.uk> wrote:
> >> What I was thinking of whas that a ppx rewriter could get whatever
> >> expression as attributes, but what remains after applying all rewriters
> >> must be included in a subset that could map to a type like (maybe a bit
> >> too restricitve)
> >>
> >> type expr =
> >> | List of expr list
> >> | Sum of string * expr
> >> | Cst of string
> >>
> >
> > This interface can be provided by:
> >
> > ------
> > (* Ast.mli *)
> >
> > type expr
> >
> > type simple_expr = | List of expr list
> > | Sum of string * simple_expr
> > | Cst of string
> >
> > val simplify_expr: expr -> simple_expr
> >
> > ------
> > (* Ast.ml *)
> >
> > type expr = Parsetree.expression
> >
> > type simple_expr =
> > | List of expr list
> > | Sum of string * simple_expr
> > | Cst of string
> >
> > let simplify_expr expr = ...
> >
> > ------
> > (* Parsetree.mli *)
> >
> > type expression = ...
> >
> > val of_ast_expr: Ast.expr -> expression
> >
> > ------
> > (* Parsetree.ml *)
> >
> > type expression = ...
> >
> > external of_ast_expr: Ast.expr -> expression = "%identity"
> >
> > ------
> >
> > This would allow users to use the fixed simple interface, or the full
> > parsetree interface.
> >
> >
> > _______________________________________________
> > wg-camlp4 mailing list
> > wg-camlp4 at lists.ocaml.org
> > http://lists.ocaml.org/listinfo/wg-camlp4
> _______________________________________________
> wg-camlp4 mailing list
> wg-camlp4 at lists.ocaml.org
> http://lists.ocaml.org/listinfo/wg-camlp4
>
--
-- Regards, Hongbo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/wg-camlp4/attachments/20130214/29ea98d2/attachment.html>
More information about the wg-camlp4
mailing list