Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How fast is Data.Array?

The documentation of Data.Array reads:

Haskell provides indexable arrays, which may be thought of as functions whose domains are isomorphic to contiguous subsets of the integers. Functions restricted in this way can be implemented efficiently; in particular, a programmer may reasonably expect rapid access to the components.

I wonder how fast can (!) and (//) be. Can I expect O(1) complexity from these, as I would have from their imperative counterparts?

like image 370
R. Martinho Fernandes Avatar asked Sep 02 '11 21:09

R. Martinho Fernandes


1 Answers

In general, yes, you should be able to expect O(1) from ! although I'm not sure if thats guaranteed by the standard.

You might want to see the vector package if you want faster arrays though (through use of stream fusion). It is also better designed.

Note that // is probably O(n) though because it has to traverse the list (just like an imperative program would). If you need a lot of mutation you can use MArray orMVector.

like image 194
alternative Avatar answered Sep 29 '22 17:09

alternative