[Haskell] TArray?

Sebastian Sylvan sebastian.sylvan at gmail.com
Tue Dec 13 08:10:46 EST 2005

On 12/13/05, Tomasz Zielonka <tomasz.zielonka at gmail.com> wrote:
> On Tue, Dec 13, 2005 at 01:32:46PM +0100, Sebastian Sylvan wrote:
> > Are there plans to include a mutable array for use in the STM monad,
> > or a good reason for why this is not needed? Also, an unboxed version
> > would be nice.
> Why not use an (Array idx (TVar a)) ?

Ah.. Good thinking!
This should work for in the STM monad for anything you would IOArray
for in the IO monad,  if you write proper instances for MArray of

It's a bit inefficient, an extra indirection (compared to a primitive
implementation) but that shouldn't matter too much for the general
case. And the TVars themselves introduces some extra overhead, I would
suppose (which could be per-array rather than per-element, without
losing the property that only writes to the same element causes
It gets even trickier if you want an unboxed mutable array in the STM monad.

But still, it's useful and I think a mutable array for the STM monad
should be in the libraries. It could be implemented as an Array at
first, and perhaps later switch to a more efficient representation.


Sebastian Sylvan
UIN: 44640862

More information about the Haskell mailing list