From: Brian H. <bri...@ql...> - 2003-06-19 15:20:16
|
On Thu, 19 Jun 2003, John Max Skaller wrote: > Brian Hurt wrote: > > > On Tue, 17 Jun 2003, John Skaller wrote: > > >>Can't you initialise the empty slots with Obj.magic(0)? > >> > > No. What if it's an array of floats, which is unboxed? > > > Ah. > > > > If you don't have a convient default, use a 'a option Dynarray.t. > > > No way. That's a hack to support a faulty implementation. > I want a 'a Dynarray.t, the *filled* slots always have that type. > I don't see why I should change the type to suit an implementation > that can't handle the idea of a variable length array properly. As I can't use Obj.magic() if it's an array of floats, the only other option I have is to make *everything* a 'a option Dynarray.t implicitly- make the internal array a 'a option array instead of just a 'a array. Which means if it's a dynarray of ints, the ints are not unboxed. Futhermore, if I understand things correctly, the ints aren't unboxed in the option variable either- meaning that I've now added two dereferences and two extra words for every integer in the array- when I can instead just use an integer array in the current implementation. > > 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. > > > Note: in the current API there is no way to get access to an element with > > a null value. So you don't ever have to worry about distinguishing null > > values from sensible values. So it's still safe if the null value would > > otherwise have meaning. > > > I have examples where I CANNOT construct a dummy value. > The fact that the value is not accessible with > an array access cannot remove a requirement > an object may have to connect to other objects. 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. > It could be there is NO good solution in Ocaml. > In that case, use a C solution. I want this > data structure to work exactly right, and I need > it precisely *because* I can't define it myself. Feel free to submit code. Brian |