Faster Array#/MutableArray# copies

Roman Leshchinskiy rl at cse.unsw.edu.au
Tue Mar 1 16:50:27 CET 2011


Simon Marlow wrote:
> On 01/03/2011 11:55, Roman Leshchinskiy wrote:
>
>>
>> Would it, in theory, be possible to have an "unpacked" array type? That
>>  is, could we have constructors for which the length of the closure is
>> determined dynamically at runtime?
>
> Certainly, but the amount of effort to implement depends on what you
> want to support. e.g. do you want to support {-# UNPACK #-} on primitive
> array types in a constructor field?  That's probably quite hard.  I
> believe Duncan Coutts has been thinking along similar lines, we talked
> about it once.

I can see that supporting this would be rather hard:

data T a = T {-# UNPACK #-} (Array# a)

We would have to allow Array# to point to the middle of a closure and it's
far from obvious how to initialise this since we don't have Array#
literals.

> Or were you thinking of something more restricted?

Yes, I was thinking of some special syntax. Something along these lines:

data T a = T {a}

f x = T {x x x}
g (T {x y z}) = x
h (T xs) = xs{0}

I'm not seriously suggesting this syntax, this is just to demonstrate the
general idea. In the last function, it shouldn't be possible to do
anything with xs except indexing and taking the length.

This would be much easier, right?

Of course, we would also want this for byte arrays...

Roman






More information about the Glasgow-haskell-users mailing list