Browse thread
C++/C# inheritance is bad?
[
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: | blue storm <bluestorm.dylc@g...> |
| Subject: | Re: Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?] |
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.