caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe <Jean-Christophe.Filliatre@lri.fr>
To: David Teller <David.Teller@univ-orleans.fr>
Cc: OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Pattern-matching destructors ?
Date: Tue, 16 Oct 2007 19:44:27 +0200	[thread overview]
Message-ID: <4714F87B.8040807@lri.fr> (raw)
In-Reply-To: <1192548046.6061.18.camel@Blefuscu>

David Teller a écrit :
> 
>  I'm currently working on static analysis of JavaScript 2. For this, I
> need to keep lots of informations in each node of my AST, including
> things such as line/column (for better error messages), unique
> identifier (for storing inferred information), etc. As things progress,
> I fear that the number of such informations is growing prohibitive and
> very much getting into the way of pattern-matching.

I don't see why a lot of information in AST nodes is getting into the 
way of pattern-matching. When decorating ASTs, you basically replace a 
type definition such as

type t =
   | A
   | B of b
   | C of string * t * t
   | D of t list

by two mutual recursive types

type t =
   { node : t_node;
     ... a lot of information here, in other fields ... }

and t_node =
   | A
   | B of b
   | C of string * t * t
   | D of t list

As you can see, this is a purely local modification: three lines were 
inserted (between "type t" and "=").

As for pattern-matching, this is exactly the same: the modification is 
only local. Indeed, your recursive function over type t, which was 
looking like

let rec f = function
   | A -> ...
   | B b > ...
   | C (s, t1, t2) -> ... (f t1) ... (f t2) ...
   | D l -> ...

is turned into

let rec f t =
   f_node t.node

and f_node = function
   | A -> ...
   | B b > ...
   | C (s, t1, t2) -> ... (f t1) ... (f t2) ...
   | D l -> ...

Again we only inserted new lines between "let rec f" and "= function".

I agree that nested pattern-matching is slightly different, though. But 
as already said by somebody else, you can match against field node only, 
which looks like

   | C (s, {node=A}, {node=D l}) -> ...

I don't see that as really intrusive.

Hope this helps,
--
Jean-Christophe


  parent reply	other threads:[~2007-10-16 17:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-16 15:20 David Teller
2007-10-16 17:09 ` [Caml-list] " Alain Frisch
2007-10-16 17:28 ` Jon Harrop
2007-10-16 17:44 ` Jean-Christophe [this message]
2007-10-16 18:53   ` David Teller

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=4714F87B.8040807@lri.fr \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=David.Teller@univ-orleans.fr \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).