Simon Marlow wrote:
> Actually, I'm slightly concerned about your use of small arrays: the static
> (one-off) cost of allocating an array is quite high compared to eg. tuples
> or records.  Are arrays the only solution here?

You're right of course that arrays are quite expensive, but 
it is not clear to me whether this is an inherent property of
arrays or an artifact of the current implementation.

At least part of it is inherent, because of the extremely
general nature of Haskell's arrays (use of Ix, arbitrary
bounds).  I've never understood the advantages of these
arrays over a more primitive mechanism (indexed by integers
starting at 0), with the fancier arrays built on top of
the primitive arrays in a library.  But this is not a battle
I'm prepared to fight right now!

As to whether arrays are the only solution, well, no.
Tuples are out because the size is not necessarily known
in advance.  Or even if the size is known, you may
expect it to change several times during development.
Lists are a posibility, but, when I say "short,
that might be as high as maybe 256.  Some tree-like
implementation of arrays, such as Braun trees would 
not be unreasonable.  But arrays seem like the most
natural choice.  It would be a shame it steer programmers
away from arrays just because they are disproportionately
expensive.

Chris

Reply via email to