Contiguous arrays with variable length, such as C++'s std::vector
, have been a major sequential container for languages whose evaluation is eager. However, it has been commonly considered that contiguous arrays do not mix well with lazy evaluation. Indeed, Array
s that Haskell provides are strictly evaluated for its entries. Not to mention that strictly evaluated arrays cannot have infinitely many entries, unlike lazily evaluated lists can.
Yet I don't think arrays cannot be lazily evaluated anyway. I aimed to build a datastructure that can represent infinitely many entries like lazily evaluated lists can, while still being randomly accessible. To give a sketch, I think such datastructure can be implemented as cached lists. That means, the datastructure could consist of a strictly evaluated array and a lazily evaluated linked list, where the strict array acts as caches for already identified entries, and where the lazy list contains unevaluated entries. This should give amortized random access.
Yet still, I don't think Haskell can do this natively. All memory allocation/deallocation operations that Haskell provides are bound within the IO
monad. If the idea above can be implemented in our machines anyway, I would conclude that this is just language design fault of Haskell. So can contiguous arrays be lazily evaluated anyway? If so, what programming languages do have that?