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
Extracting common information
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-05-24 (11:31)
From: Romain <d@d...>
Subject: Re: [Caml-list] Extracting common information

Note that you can replace your pattern-matching with something like:

let ud_type type =
   match type with
   | Pointer(ud,_) -> ud

But although it is more factorized (which is good) it doesn't solve your 

One solution which I like better is something like:

type userdata = ... whatever you want (code location...) ...
type 'a node = {
   user_data: userdata;
   node: 'a;
type type_tree =
   Primitive of string
| Pointer of type_tree node
type expr_tree =
   Unary of string * expr_tree node
| Binary of string * expr_tree node * expr_tree node

Now instead of matching on a type_tree x, you'll match on x.node. And if 
you want the user data you just use x.user_data.

Hope it helps.

Romain Bardou