Version française
Home     About     Download     Resources     Contact us    
Browse thread
Transforming of ASTs and polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Transforming of ASTs and polymorphic variants
On Wed, 2007-04-25 at 05:19 +0100, Joel Reymont wrote:
> My apologies if this is a beginners question...
> 
> I have two ASTs in different modules that look very much alike in  
> that some constructors have the same name and type name. When I  
> transform that ASTs I end up "re-applying" the similarly named  
> constructor and arguments. This is best explained with an example.
a.ml:

type typ = [
   | `Integer
   | `Double
   | `String
   | `Boolean
]

b.ml:

type ty = [
   | `Integer
   | `Double
   | `String
   | `Boolean
   | `Void
]

A transformation function would be

let conv_type (x:A.typ): B.ty = match x with
   | x -> (x : A.typ :> B.ty)

A simpler implementation:

let conv_type x = (x : A.typ :> B.ty)

will also work in this case.



-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net