Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] productivity improvement
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oleg <oleg_inconnu@m...>
Subject: Re: [Caml-list] productivity improvement
On Thursday 18 July 2002 07:54 pm, William Lovas wrote:
> On Thu, Jul 18, 2002 at 07:14:06PM -0400, Oleg wrote:
> > However, the C++ version looks more "extensible" to me: Suppose that in a
> > while, you decide that you want your "node" to be not only Leaf or Unop
> > or Binop, but also Triop:
> >
> > type 'a node = Leaf of 'a | Unop of ('a->'a) * 'a node | Binop of ('a *
> > 'a -> 'a) * 'a node * 'a node | Triop of ('a * 'a * 'a -> 'a) * 'a node *
> > 'a node * 'a node;;
> >
> > You will need to modify the original node type and function "eval" by
> > adding an extra pattern to "match" statement, and then recompile everying
> > that depends on it. At the same time, with C++ the type of node remains
> > the same. You just need to derive a new class  from it:
> >
> > [snip]
> >
> > Recompiling isn't necessary. In fact, "old code" may call "new code" if
> > you happen to pass it a node that happens to be a triop.
>
> Yes, but what if you decide to add a new function on nodes?  Like say,
> typecheck, or eval2, with slightly different semantics?  In the O'Caml
> version, it's as simple as that -- add a new function and run with it.
> With the C++ version, though, now you have to modify *every* *single*
> *class* that inherits from node, and recompile them all.
[...]

Not really. Run-time type identification (RTTI) and a "switch" statement 
should work in a free (non-member) function just like O'Caml's "match" AFAIK.

Regards,
Oleg
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners