English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2007-04-25 (04:19)
From: Joel Reymont <joelr1@g...>
Subject: Transforming of ASTs and polymorphic variants
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.


type typ =
   | Integer
   | Double
   | String
   | Boolean


type ty =
   | Integer
   | Double
   | String
   | Boolean
   | Void

A transformation function would be

let conv_type = function
   | A.Integer -> B.Integer
   | A.String -> B.String
   | A.Boolean -> B.Boolean

I don't want to share types between ASTs since, like above, some of  
them may be supersets of others. How can I improve this with  
polymorphic variants?

	Thanks, Joel