IArray and MArray

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
Wed, 11 Apr 2001 14:19:50 +0200 (CEST)

Is it important to keep the current definition of IArray and MArray
classes? I would like to change class operations, without changing
the interface, i.e. turn methods into ordinary overloaded functions
and have different methods. It would affect users making their own
instances of these classes, but not users of these instances.

The problem is that translation of the index to an Int is coupled with
actual array operations. It's not possible to omit the translation with
the range check in an overloaded way; such operations must be coded
separately for each element type, which is quite painful. It's not
possible to add a method which specifies indexing by Int, because there is
no reasonable default definition, except using (!!) on the index range:
the class Ix doesn't define translation from Int to indices.

Many bulk operations don't need indices but just iterate over the array:
elems, listArray, amap, thaw, freeze, (==), compare (actually compare
is a more complex issue). The performance is horrible if tight loops
do the translation. But if the needed functionality is not in the array,
the operation must be coded for each type separately instead of letting
the compiler do the specialization, and some of these must be matched
with rules.

Class operations define too much. Translation of indices to Ints with
bounds checking is done in the same way for all arrays. These operations
must be polymorphic wrt. index, so they don't have a choice. But they
have to hardwire the translation into individual methods.

I would let operations in IArray and MArray work on Ints and change
current methods to functions overloaded over the array and the index.

Marcin 'Qrczak' Kowalczyk