Browse thread
Extracting common information
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Romain <d@d...> |
| Subject: | Re: [Caml-list] Extracting common information |
Hi,
Note that you can replace your pattern-matching with something like:
let ud_type type =
match type with
Primitive(ud,_)
| Pointer(ud,_) -> ud
But although it is more factorized (which is good) it doesn't solve your
problem.
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