Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Romain <d@doomeer.com>
To: Niko Matsakis <niko@alum.mit.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Extracting common information
Date: Thu, 24 May 2007 13:31:30 +0200	[thread overview]
Message-ID: <46557792.5090207@doomeer.com> (raw)
In-Reply-To: <E7A015DC-1733-4752-BE63-78113DBA3D5B@alum.mit.edu>

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


  reply	other threads:[~2007-05-24 11:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-24 11:04 Niko Matsakis
2007-05-24 11:31 ` Romain [this message]
2007-05-24 11:44 ` [Caml-list] " Bünzli Daniel
2007-05-24 14:09 ` skaller
2007-05-24 14:23 ` Stephen Weeks
2007-05-24 18:00   ` Peter Ilberg
2007-05-28 19:00     ` Niko Matsakis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46557792.5090207@doomeer.com \
    --to=d@doomeer.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=niko@alum.mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox