From: John M. S. <sk...@oz...> - 2003-06-20 03:41:29
|
Brian Hurt wrote: >>C++ vector does this correctly. >> > > At the cost of emitting a whole new wad og object code for every single > type you put into a vector. Vector<int> requires the compiler to produce > a whole vector class to deal with ints, seperate from Vector<short>, > Vector<char>, Vector<void *>, etc. Your comparison is unfair and untrue. If you make the equivalent vector to ocaml, you'd make a vector of pointers. It is in fact easy and common practice to specialise vector on pointers to use the code for a vector<void*> plus casts wrapped in the template. Most compilers will optimise this to the calls to the void* specialisation if the wrappers are inline. So no code bloat. On the contrary, C++ has a built-in mechanism for handling specialisations and Ocaml does not, so in this area it is way ahead of Ocaml: put another way: if you have unboxed types and pointers, you can always use boxed types. The reverse is not true. Ocaml is in fact based on a faulty type system, which fails to recognize that copying values cannot be handled polymorphically: it cheats by using boxing. There are a few areas where this fault is evident, for example recursive types: the usual definition is in fact quite wrong: the unfold of a recursive type is a distinct type. Its only isomorphic to the original if the types are replaced by pointers. The principal problem in C++ here is the lack of a garbage collector. The code bloat from the specialisations is the price for high performance: ocaml is doing that too with unboxed arrays of floats etc .. but it will never compete with C++ in this area: the ocaml team has to 'hack' the underlying implementation to gain performance. The C++ end user can do it easily and more reliably. In fact.. its the default :-) > In this case, you're going to be using a 'a option Dynarray.t one way or > another. The question is wether you can ever get rid of the option part. Nah, just box the floats. Should be easy. Make the underlying array type int. Use 0 as the null value. Use casts to convert incoming and outgoing values. Easy. Floats stay boxed though. I don't care. -- John Max Skaller, mailto:sk...@oz... snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 |