Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Niko Matsakis <niko@alum.mit.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Extracting common information
Date: Fri, 25 May 2007 00:09:47 +1000	[thread overview]
Message-ID: <1180015787.6122.18.camel@rosella.wigram> (raw)
In-Reply-To: <E7A015DC-1733-4752-BE63-78113DBA3D5B@alum.mit.edu>

On Thu, 2007-05-24 at 13:04 +0200, Niko Matsakis wrote:
> Hello,

> > type type_tree = Primitive of string | Pointer of type_tree
> > and  expr_tree = Unary of string * expr_tree |
> >                  Binary of string * expr_tree * expr_tree

> This seemed like it should work reasonably well, but then I realized  
> I would want to thread along some annotation to store the types, line  
> numbers, and things like that.  Since these annotations will change  
> between compiler passes, I thought I would use a variant type like so:
> 
> > type 'ud type_tree = Primitive of 'ud * string |
> >                      Pointer of 'ud * 'ud type_tree
> > and 'ud expr_tree = Unary of 'ud * string * 'ud expr_tree |
> >                     Binary of 'ud * string * 'ud expr_tree * 'ud  
> > expr_tree
> > etc
> 
> but then I ran into the problem that I sometimes want to be able to  
> extract the user data without reference to the type of tree involved,  
> and I can see no easy way to do that beyond:
> 
> > let ud_type type =
> >   match type with
> >     Primitive(ud,_) ud |
> >     Pointer(ud,_) ud
> > etc
> 
> Obviously, that is unappealing.

That doesn't matter: what you have done is the best way, except
the type for source references should be concrete, not a parameter.

Although you could factor this by separating the source
location from the term .. that's a bad idea because you will
be tempted to throw out the source location when analysing
the terms .. which prevents you emitting good errors.

Putting the source location directly in the terms FORCES
you to calculate a reasonable location for every term you
synthesise by a rewriting rule (via the type system), 
which is a good thing.

There is another way though .. just add a term like:

	`Source of src_loc * tree

which says 'my child was produced from this source location'.
I don't recommend this though, precisely because it can be used
wherever you like .. or not used at all.


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


  parent reply	other threads:[~2007-05-24 14:09 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 ` [Caml-list] " Romain
2007-05-24 11:44 ` Bünzli Daniel
2007-05-24 14:09 ` skaller [this message]
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=1180015787.6122.18.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --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