<br><br><div class="gmail_quote">On Thu, Feb 14, 2013 at 6:48 AM, Wojciech Meyer <span dir="ltr"><<a href="mailto:wojciech.meyer@gmail.com" target="_blank">wojciech.meyer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Another way of providing these simple asts would be to treat any<br>
flavor of variants uniformly and then in the end transform it back to<br>
what was expected (only if it's needed).<br>
<br>
(I don't know if that what wasn't originally proposed by Pierre).<br>
<br>
So regardless if it's a polymorphic variant, GADT, or plain data type,<br>
we would have one AST - the common denominator and what matters of<br>
these is usually the tag name and general signature. Once we have that<br>
we will match from that simple AST our type driven plugin that will<br>
generate JSON, XML, visitors. etc The idea is to have something that<br>
is good enough and reflects general structure to get rid of<br>
complicated parse tree or/and quotations on the LHS and/or factor out<br>
the common pattern matchers using some meta object.<br>
<br>
We could go even further and generate all the bolier plate pattern<br>
matchers via visitor pattern by default, of course it needs to be<br>
thought - but the idea is to not look at types at all - now it turns<br>
to be it's already a meta-meta programming.<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div>That's how ast works in Fan, constructor names are not associated with type at</div><div>all.</div><div>So, suppose you have a function </div><div>
sem_of_list, it works for all syntax categories, in Camlp4 you need to write sem_of_list_ctyp, sem_of_list_expr,.....</div><div><br></div><div>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 href="http://a.ml">a.ml</a>, 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</div>
<div><br></div><div>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.</div><div><br></div><div><br></div><div>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
On Wed, Feb 13, 2013 at 5:56 PM, Leo White <<a href="mailto:lpw25@cam.ac.uk">lpw25@cam.ac.uk</a>> wrote:<br>
>> What I was thinking of whas that a ppx rewriter could get whatever<br>
>> expression as attributes, but what remains after applying all rewriters<br>
>> must be included in a subset that could map to a type like (maybe a bit<br>
>> too restricitve)<br>
>><br>
>> type expr =<br>
>> | List of expr list<br>
>> | Sum of string * expr<br>
>> | Cst of string<br>
>><br>
><br>
> This interface can be provided by:<br>
><br>
> ------<br>
> (* Ast.mli *)<br>
><br>
> type expr<br>
><br>
> type simple_expr = | List of expr list<br>
> | Sum of string * simple_expr<br>
> | Cst of string<br>
><br>
> val simplify_expr: expr -> simple_expr<br>
><br>
> ------<br>
> (* Ast.ml *)<br>
><br>
> type expr = Parsetree.expression<br>
><br>
> type simple_expr =<br>
> | List of expr list<br>
> | Sum of string * simple_expr<br>
> | Cst of string<br>
><br>
> let simplify_expr expr = ...<br>
><br>
> ------<br>
> (* Parsetree.mli *)<br>
><br>
> type expression = ...<br>
><br>
> val of_ast_expr: Ast.expr -> expression<br>
><br>
> ------<br>
> (* Parsetree.ml *)<br>
><br>
> type expression = ...<br>
><br>
> external of_ast_expr: Ast.expr -> expression = "%identity"<br>
><br>
> ------<br>
><br>
> This would allow users to use the fixed simple interface, or the full<br>
> parsetree interface.<br>
><br>
><br>
> _______________________________________________<br>
> wg-camlp4 mailing list<br>
> <a href="mailto:wg-camlp4@lists.ocaml.org">wg-camlp4@lists.ocaml.org</a><br>
> <a href="http://lists.ocaml.org/listinfo/wg-camlp4" target="_blank">http://lists.ocaml.org/listinfo/wg-camlp4</a><br>
_______________________________________________<br>
wg-camlp4 mailing list<br>
<a href="mailto:wg-camlp4@lists.ocaml.org">wg-camlp4@lists.ocaml.org</a><br>
<a href="http://lists.ocaml.org/listinfo/wg-camlp4" target="_blank">http://lists.ocaml.org/listinfo/wg-camlp4</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>-- Regards, Hongbo