<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/01/bbed03c4ad81907e983814572437326f"
  from="Yoann Padioleau &lt;padator@w...&gt;"
  author="Yoann Padioleau"
  date="2009-01-21T20:09:07"
  subject="Re: Visitor in OCaml"
  prev="2009/01/b6e5615f0ddcff7795d510d626bf48fa"
  next="2009/01/c019f81e9e51e4ed916dd8defc2922e2"
  prev-in-thread="2009/01/0eb7ca2a446affb91a9277e3c12af881"
  next-in-thread="2009/01/9828bde42f61b10aa9f08a2126773cd0"
  prev-thread="2009/01/7d9ffe8f9682d9fa8b4a85b38c339f33"
  next-thread="2009/01/000cddff1b409b39cd14cc392083ce8a"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="C++/C# inheritance is bad?">
<msg 
  url="2009/01/f038b8a453e89bfa6350495a826080fe"
  from="Kuba Ober &lt;ober.14@o...&gt;"
  author="Kuba Ober"
  date="2009-01-16T15:18:51"
  subject="C++/C# inheritance is bad?">
<msg 
  url="2009/01/7f3ed02f83caca6c67c43c70d569e674"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-16T15:58:08"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/62a2d4cfa48d2f7cdc9e412c097ea6e8"
  from="Jan Kybic &lt;kybic@f...&gt;"
  author="Jan Kybic"
  date="2009-01-16T16:29:10"
  subject="On the benefits of OO, Was: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/c69523eaafbcbe2312b568706d7a7c98"
  from="Oliver Bandel &lt;oliver@f...&gt;"
  author="Oliver Bandel"
  date="2009-01-17T12:40:24"
  subject="Re: On the benefits of OO, Was: [Caml-list] C++/C# inheritance is bad?">
</msg>
</msg>
</msg>
<msg 
  url="2009/01/6cca6c9feefd88566702defdd9eb4640"
  from="Raoul Duke &lt;raould@g...&gt;"
  author="Raoul Duke"
  date="2009-01-16T18:27:41"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/5977e5c50685f9511c2a7aaeb88f2aaa"
  from="Kuba Ober &lt;ober.14@o...&gt;"
  author="Kuba Ober"
  date="2009-01-16T21:42:40"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/1688f5de4636fc2a074a556bdd4e13c5"
  from="Sashan Govender &lt;sashang@g...&gt;"
  author="Sashan Govender"
  date="2009-01-17T03:14:40"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/3da7c22bc8951acf11dc387c75d70ce3"
  from="Kuba Ober &lt;ober.14@o...&gt;"
  author="Kuba Ober"
  date="2009-01-17T14:07:23"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/0d0df2a5f73e6806a082ed1385428205"
  from="Stefano Zacchiroli &lt;zack@u...&gt;"
  author="Stefano Zacchiroli"
  date="2009-01-18T06:24:43"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/01/bf9090ae9b10f70576fe56884cc0bb1d"
  from="Jon Harrop &lt;jon@f...&gt;"
  author="Jon Harrop"
  date="2009-01-17T13:23:25"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/9830bc229413613d2df787f6c4190432"
  from="Kuba Ober &lt;ober.14@o...&gt;"
  author="Kuba Ober"
  date="2009-01-17T14:35:25"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/484729b8c91b7ed08f7a809ef4800784"
  from="Jon Harrop &lt;jon@f...&gt;"
  author="Jon Harrop"
  date="2009-01-17T16:55:53"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/bc0b728019ecc0ed06c6c620d4829306"
  from="Kuba Ober &lt;ober.14@o...&gt;"
  author="Kuba Ober"
  date="2009-01-17T21:22:22"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/b83f81eef8ccb535ebb9797ff38dee68"
  from="Jon Harrop &lt;jon@f...&gt;"
  author="Jon Harrop"
  date="2009-01-17T22:14:04"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/e6aec16698cc330e90186b9637b316b6"
  from="David Teller &lt;David.Teller@u...&gt;"
  author="David Teller"
  date="2009-01-17T23:29:08"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
<msg 
  url="2009/01/81422a330b59f6967afaba609aa0aa1c"
  from="Jon Harrop &lt;jon@f...&gt;"
  author="Jon Harrop"
  date="2009-01-17T23:46:02"
  subject="Re: [Caml-list] C++/C# inheritance is bad?">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/01/9d3495098b6736864d7a911f80eacf02"
  from="Yoann Padioleau &lt;padator@w...&gt;"
  author="Yoann Padioleau"
  date="2009-01-19T16:22:12"
  subject="Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?]">
<msg 
  url="2009/01/15619ef0d6556c727c807856c0540121"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-01-19T16:41:37"
  subject="Re: Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?]">
<msg 
  url="2009/01/982cca226b947ab9e2f9f544aa708026"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-19T17:49:27"
  subject="Re: Visitor in OCaml [was Re: [Caml-list] C++/C# inheritance is bad?]">
</msg>
<msg 
  url="2009/01/0eb7ca2a446affb91a9277e3c12af881"
  from="Christophe TROESTLER &lt;Christophe.Troestler+ocaml@u...&gt;"
  author="Christophe TROESTLER"
  date="2009-01-19T17:52:12"
  subject="Re: Visitor in OCaml">
</msg>
<msg 
  url="2009/01/bbed03c4ad81907e983814572437326f"
  from="Yoann Padioleau &lt;padator@w...&gt;"
  author="Yoann Padioleau"
  date="2009-01-21T20:09:07"
  subject="Re: Visitor in OCaml">
<msg 
  url="2009/01/9828bde42f61b10aa9f08a2126773cd0"
  from="Yaron Minsky &lt;yminsky@g...&gt;"
  author="Yaron Minsky"
  date="2009-01-22T04:03:22"
  subject="Re: [Caml-list] Re: Visitor in OCaml">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
"blue storm" &lt;bluestorm.dylc@gmail.com&gt; writes:

&gt; On 1/19/09, Yoann Padioleau &lt;padator@wanadoo.fr&gt; wrote:
&gt;&gt; What we want is really give code like
&gt;&gt;
&gt;&gt; let my_analysis program =
&gt;&gt;  analyze_all_expressions program (fun expr -&gt;
&gt;&gt;    match expr with
&gt;&gt;    | FunCall (e, es) -&gt; do_something()
&gt;&gt;    | _ -&gt; &lt;find_a_way_to_recurse_for_all_the_other_cases&gt;
&gt;&gt;  )
&gt;&gt;
&gt;&gt; The problem is how to write analyze_all_expressions
&gt;&gt; and find_a_way_to_recurse_for_all_the_other_cases.
&gt;
&gt; You should have a look at the Camlp4 "metaprogramming" facilities :
&gt; http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator

I've been there. I once implemented in camlp4 my own map-generator but
I now prefer not using fancy features or langage extensions. I prefer
to go back to basics. My solution does not use any fancy
stuff; just higher order functions, the continuation idiom,
and records. People reading your code, or downloading your
code then do not need to care about camlp4 (or objects).

Moreover, sometimes you need to do things slightly differently
from what is auto-generated and it becomes painful. For instance
it's possible to auto-generate the string_of_xxx for each
type xxx, but at some point you may want to do the printing
slightly differently, hide a few things, do some indentation
work (and use the Format library), etc, and at this point
you will have to write the tedious code. Camlp4
metaprogramming may save you some time at the beginning, but but do you really 
win that much time in the end ? 



&gt;
&gt; You would write something like :
&gt; let my_analysis program =
&gt;   let analysis = object (self)
&gt;     inherit fold as super
&gt;     method expr = function
&gt;     | FunCall (e, es) -&gt; do_something (); self
&gt;     | other -&gt; super#expr other
&gt;   end in analysis#expr
&gt;
&gt; While sometimes a bit hairy, the object oriented layer makes it easy
&gt; to use a refine mapper or folders without writing all the heavy
&gt; plumbing yourself.

Thx, always interesting to see different ways to solve 
the same problem.

</contents>

</message>

