[Haskell-cafe] Data.IArray rant

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Tue Sep 6 16:14:09 CEST 2011

Roman Leshchinskiy <rl at cse.unsw.edu.au> writes:

> On 03/09/2011, at 03:04, Ivan Lazar Miljenovic wrote:
>> On 3 September 2011 11:38, Evan Laforge <qdunkan at gmail.com> wrote:
>>>  The result is that my first contact with haskell
>>> arrays left me with the impression that they were complicated, hard to
>>> use, and designed for someone with different priorities than me.  Of
>>> course, Data.Vector didn't exist back then, but if someone were new to
>>> haskell now I would recommend they skip Data.IArray and head straight
>>> for vector.
>> To an extent, I wonder how much of this has been that arrays were
>> considered to be bad in Haskell, so no-one used them and no-one
>> bothered to try and improve the API much (and instead went and created
>> Vector, etc.).

No, arrays were not considered to be bad, they were designed
with parallelism in mind. It’s just that no-one has really put
much effort into the implementation (partly because during the
first few years no-one wrote anything that used arrays much, and
then there’s a feedback loop no usage=>no implementation
effor=>no usage. Also there seem to be some misunderstandings.

> It's rather that some considered the IArray API to be
> inadequate most of the time. Really, H98 arrays aren't very
> good at anything they do. For collective operations, you are
> supposed to convert the array to a list, work on the list and
> then convert it back to an array which just seems wrong.

I am unconvinded that this is any more wrong than using a for
loop in an imperative language. Remember that the lists are
lazy, so it’s misleading to say “convert the array to a list”
since what happens most of the time is that elements are taken
out of the array and passed to the processing function and then
thrown away before the next element is processed.

> Multidimensional arrays can't be sliced and diced in the style
> of Repa or NumPy.

I’m not familiar with Repa or NumPy, but what can they do that
cannot be done with judicious use of ixmap, which is a very
powerful mechanism.

> In general, H98 arrays seem to have been designed with the
> goal of providing a container with O(1) indexing. They do
> that, I suppose, although they aren't very well integrated
> with the rest of the language

Can you give examples?

> and they have conceptual problems (such as requiring two
> bounds checks for one array access).

Assuming that you mean that for safe array access where nothing
is known about the index at compile time, since any sort of
array has at least a beginning and an end, they all require two
bounds checks. Once you do know something about the index, it’s
a question of implementation.

Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk

More information about the Haskell-Cafe mailing list