Is there an efficient fixed-size list library in Haskell? I think the IArray
interface is somewhat complicated when one only wants arrays indexed by natural numbers [including zero]. I want to write code like
zeroToTwenty :: Int -> FixedList Int
zeroToTwenty 0 = createFixedList 21 []
zeroToTwenty n = zeroToTwenty (n-1) `append` n
my naive solution is below.
Edit: Sorry for the lack of context; I want a datastructure that can be allocated once, to avoid excessive garbage collection. This was in the context of the merge
routine for merge sort, which takes two sorted sublists and produces a single sorted list.
How about using the vector package? It provides very efficient growable vectors with a list-like interface, and O(1) indexing.
I would probably use Vector as Don Stewart suggests, but you can use a list-like interface with IArray
by using ListLike.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With