[Haskell-cafe] Data.IArray rant

Evan Laforge qdunkan at gmail.com
Tue Sep 6 21:23:25 CEST 2011


> 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.

I don't think it's misleading to say "convert to a list".  Without the
presence of some fusion-esque optimization, the entire list is created
and destroyed.  It's nice if it can be done incrementally, but that's
still a lot of garbage.  And for a concrete example, consider
concatenating a bunch of arrays.  Unless it gets deforested, you have
to copy each element a couple of times, since there is intermediate
list concatenation.  And then this kind of API is incompatible with
unboxing... if you later decide to unbox the data type then I don't
think you could ever get the intermediate list approach to work, since
it's boxed by nature.

> 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.

I spent hours messing with ixmap before getting something that seemed
to work right.  Maybe I just have more trouble than most with it, but
though it may be powerful it's certainly not easy to use!  After
spending too much time on it I learned to just convert to a list and
back.



More information about the Haskell-Cafe mailing list