Version française
Home     About     Download     Resources     Contact us    
Browse thread
AST transformation and scrapping boilerplate code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: Re: [Caml-list] AST transformation and scrapping boilerplate code
A combination of polymoprhic variants with generated map and fold  
traversals would be incredibly useful in AST transformations.

Imagine the case where some constructors are "shared" between  
different ASTs, e.g. type ty = [`A a|`B b] in one module and type ty  
= [`B b|`C c|` d] in another. You need to transform the first type  
into the second.

You could use the example below and add matches for special cases  
where either the target constructor is different or different actions  
need to be taken.

Is adding polymorphic variants to camlp4 something that can be  
accomplished by mere mortals? Any pointers on where to start and how  
to proceed?

	Thanks, Joel

On Apr 30, 2007, at 9:21 AM, Nicolas Pouillard wrote:

> However these to generators don't handle polymorphic variants.
> [...]
> class map = Camlp4Filters.GenerateMap.generated;;
> class fold = Camlp4Filters.GenerateFold.generated;;
>
> let strip_postions = object inherit map as super
>  method expr e =
>    match super#expr e with
>    | TokenPos(a, _) -> a
>    | e -> e
> end

--
http://wagerlabs.com/