3 ms·
While Haskell's Array type indeed immutable, there is an incremental update function (//) :: (Ix a) => Array a b -> [(a,b)] -> Array a b that g
by tromp 3y ago
While Haskell's Array type indeed immutable, there is an incremental update function
(//) :: (Ix a) => Array a b -> [(a,b)] -> Array a b
that gives you a new updated array. As long as you no longer refer to the old instance, this is as efficient as a mutable array.
But Haskell also offers the mutable STArray and STUArray, for boxed and unboxed types [1]. These preserve their purity by being monadic.
[1] https://hackage.haskell.org/package/array-0.5.6.0/docs/Data-Array-ST.html https://hackage.haskell.org/package/array-0.5.6.0/docs/Data-...
- misja111 3y ago> As long as you no longer refer to the old instance, this is as efficient as a mutable array. On paper this is true, in reality though it probably is not. Immutable Haskell arrays are implemented with pointers, mutable arrays are implemented as contiguous memory allocations, so they have great cache locality.