Josh
> Some questions about arrays:
> It sounds like, according to this specification, there has to be a thunk
> for every element of the array. This brings up the usual trade-off: this is
> elegant and flexible, but slow.
> ??? - For generic GHC Array's, is a thunk created for each individual array
> element?
Yes, that's right.
> Or are all the elements of the Array a "forced" at once? (If this differs
> from the Library Report spec. above, it might be good to put that in the
> documentation... though personally, I'm happy with this solution.)
No they aren't.
> ------------------------------------------------------------
> ??? - As it stands, all the elements of an Array are boxed, because Array is
> a polymorphic type. Could you add {-#SPECIALISE -} pragmas to the part of
> the Prelude that defines "Array"s to get arrays of unboxed things? It sounds
> like this would be very difficult, if Arrays are implemented exactly as the
> Library report seems to describe, with a thunk for every element (or
> something equivalent.)
That is indeed difficult at the moment, because we can't specialise
a polymorphic type variable to an unboxed type like Int#.
> I think it might be useful in many situations to have an array
> in which all the elements were evaluated at once.
Yes, that's true. Rather like strictness annotations on data structures.
Not in Haskell at present, but on the wish-list for GHC.
> For one thing, you could
> unbox the elements of the array, which should make them faster.
Unboxing adds new complications, but is a huge performance win. You can do
it by hand in GHC (the libraries glaExts/MutableArray and glaExts/ByteArray),
but it's not very satisfactory.
> Or, if MutableArrays are strict in state, I could write array accessing
> functions for every type of array that I was going to use; but it seems that
> just using C would be simpler at that point...
That's more or less what glaExts/MutableArray does.
Please keep us posted of any applications you write!
Simon