From: Matthew F. <fl...@CS...> - 2002-07-23 15:54:15
|
As promised, here is a longish look at the types used in Arrays and Vectors. Array and Vector design: * The ARRAY signature includes type 'a vector. Presumably, type 'a Array.vector = type 'a Vector.vector, but no constraint makes this explicit. * MONO_ARRAY_SLICE includes type vector and type vector_slice, while the ARRAY_SLICE signature explicitly references 'a VectorSlice.slice and 'a Vector.vector. * VECTOR_SLICE doesn't include 'a vector, but has val mapi : (int * 'a -> 'b) -> 'a slice -> 'b vector val map : ('a -> 'b) -> 'a slice -> 'b vector; On the other hand, full, slice, base, vector, and concat reference 'a Vector.vector. For consistency, I'd prefer to see signature VECTOR = sig type 'a vector ... end signature VECTOR_SLICE = sig type 'a vector type 'a slice ... end signature ARRAY = sig type 'a vector type 'a array ... end signature ARRAY_SLICE = sig type 'a vector type 'a vector_slice tyep 'a array type 'a slice ... end signature MONO_VECTOR = sig type elem type vector ... end signature MONO_VECTOR_SLICE = sig type elem type vector type slice ... end signature MONO_ARRAY = sig type elem type vector type array ... end signature MONO_ARRAY_SLICE = sig type elem type vector type vector_slice type array type slice ... end structure Vector :> VECTOR structure VectorSlice :> VECTOR_SLICE where type 'a vector = 'a Vector.vector structure Array :> ARRAY where type 'a vector = 'a Vector.vector structure ArraySlice :> ARRAY_SLICE where type 'a vector = 'a Vector where type 'a vector_slice = 'a VectorSlice.slice where type 'a array = 'a Array.array structure BoolVector :> MONO_VECTOR where type elem = bool structure BoolVectorSlice :> MONO_VECTOR_SLICE where type elem = bool where type vector = BoolVector.vector structure BoolArray :> MONO_ARRAY where type elem = bool where type vector = BoolVector.vector structure BoolArraySlice :> MONO_ARRAY_SLICE where type elem = bool where type vector = BoolVector.vector where type vector_slice = BoolVectorSlice.slice where type array = BoolArray.array While semantically, this shouldn't be any different than the specification, it could effect type-error messages. For example, if I have the structure Foo: structure Foo = struct open BoolArraySlice val copyVec0 {src: vector_slice, dst: array} = copyVec {src = src, dst = dst, di = 0} end which I decide to generalize to polymorphic array slices, then just changing BoolArraySlice to ArraySlice will lead to different type-error messages: either "ubound type constructor: vector_slice" (under the specification) or "type constructor vector_slice given 0 arguments, wants 1" (under the signatures given above); and an arity error for array in either case. It's not much of an argument, but I need to replace vector_slice with 'a VectorSlice.slice under the specification, while I only need to add 'a under the sigs above. Array2: * Why not have an ARRAY2_REGION analagous to ARRAY_SLICE? Likewise, how about VECTOR2 and VECTOR2_REGION? I think the decision to separate Arrays and Vectors from their corresponding slices is a nice design choice, and I'd be in favor of extending it to multi-dimentional ones. * Should ARRAY2 have findi/find, exists, all? collate? |