[Haskell-cafe] List indexer

Alex Stangl alex at stangl.us
Sat Sep 8 08:55:39 CEST 2012


Hi,

I have written a small "wrapper" to speed random-access to a list. The
usage scenario I have in mind is a "stream" computation yielding an
infinite list, and I want to randomly access elements w/o having to
traverse the entire list from the beginning for each access.

I suspected something similar must already exist, but nothing I looked
at seemed to do the trick. IntMap seems to want a finite input list.
Ditto for the various array types, except possibly dynamic array.

Attached is the list indexer I came up with, and a small test program
(I swap the commented-out lines to switch btw. list & list index tests).
I am interested to hear any feedback on this -- whether it duplicates
something that already exists, or whether there's a better approach, and
comments on the code, etc. Also if somebody can suggest a better name
(so as not to overlay the word index too much.) I'll publish it on
hackage (or at least github) if people think it's useful. It sped up
the program I initally wrote it for enormously.

Thanks,

Alex

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ListIndex.hs
Type: text/x-haskell
Size: 2045 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120908/e4650021/attachment.hs>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ListIndexTest.hs
Type: text/x-haskell
Size: 852 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120908/e4650021/attachment-0001.hs>


More information about the Haskell-Cafe mailing list