caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "blue storm" <bluestorm.dylc@gmail.com>
To: "Yoann Padioleau" <padator@wanadoo.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?]
Date: Mon, 19 Jan 2009 17:41:35 +0100	[thread overview]
Message-ID: <527cf6bc0901190841l3247ada1kfc86847aac1445d1@mail.gmail.com> (raw)
In-Reply-To: <871vuz2rm7.fsf_-_@aryx.cs.uiuc.edu>

On 1/19/09, Yoann Padioleau <padator@wanadoo.fr> wrote:
> What we want is really give code like
>
> let my_analysis program =
>  analyze_all_expressions program (fun expr ->
>    match expr with
>    | FunCall (e, es) -> do_something()
>    | _ -> <find_a_way_to_recurse_for_all_the_other_cases>
>  )
>
> The problem is how to write analyze_all_expressions
> and find_a_way_to_recurse_for_all_the_other_cases.

You should have a look at the Camlp4 "metaprogramming" facilities :
http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator

You would write something like :
let my_analysis program =
  let analysis = object (self)
    inherit fold as super
    method expr = function
    | FunCall (e, es) -> do_something (); self
    | other -> super#expr other
  end in analysis#expr

While sometimes a bit hairy, the object oriented layer makes it easy
to use a refine mapper or folders without writing all the heavy
plumbing yourself.


  reply	other threads:[~2009-01-19 16:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16 15:18 C++/C# inheritance is bad? Kuba Ober
2009-01-16 15:58 ` [Caml-list] " Richard Jones
2009-01-16 16:28   ` On the benefits of OO, Was: " Jan Kybic
2009-01-17 12:40     ` Oliver Bandel
2009-01-16 18:27 ` Raoul Duke
2009-01-16 21:42   ` Kuba Ober
2009-01-17  3:14     ` Sashan Govender
2009-01-17 14:07       ` Kuba Ober
2009-01-18  6:24         ` Stefano Zacchiroli
2009-01-17 13:27 ` Jon Harrop
2009-01-17 14:35   ` Kuba Ober
2009-01-17 16:59     ` Jon Harrop
2009-01-17 21:22       ` Kuba Ober
2009-01-17 22:17         ` Jon Harrop
2009-01-17 23:29           ` David Teller
2009-01-17 23:49             ` Jon Harrop
2009-01-19 16:22       ` Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?] Yoann Padioleau
2009-01-19 16:41         ` blue storm [this message]
2009-01-19 17:49           ` Richard Jones
2009-01-19 17:52           ` Visitor in OCaml Christophe TROESTLER
2009-01-21 20:09           ` Yoann Padioleau
2009-01-22  4:03             ` [Caml-list] " Yaron Minsky

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=527cf6bc0901190841l3247ada1kfc86847aac1445d1@mail.gmail.com \
    --to=bluestorm.dylc@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=padator@wanadoo.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).