Johan Tibell wrote:
> On Tue, Feb 1, 2011 at 4:24 PM, Roman Leshchinskiy <[email protected]>
> wrote:
>
>> Johan Tibell wrote:
>>
>>>
>>> Does cloneArray# really have to take and return a `State# s`?
>>>
>>
>> Oops, no, it doesn't. This was purely a case of mindless copy-pasting.
>>
>
> Does this apply to any of the other primops?

I don't think so. Anything involving allocating/reading/writing
MutableArray# is impure.

> thawArray#   ::        Array#   a -> Int# -> Int# -> State# s -> (#
State# s, MutableArray# s a #)
>
>
> It seems to me that maybe thawArray# doesn't need to take a state
> token either as the input array can be copied at any point in time.

No, the operation is still impure. Suppose we had

thawArray# :: Array# a -> Int# -> Int# -> MutableArray# s a

Then, we write

f xs = let ys = thawArray# xs 0 n#
           zs = thawArray# xs 0 n#
       in e

Do ys and zs refer to the same MutableArray# in e?

> Is it
> even possible to return a MutableArray# without taking a state token as an
> input parameter?

No, for precisely this reason. In contrast to pure arrays, mutable arrays
have an "identity", hence allocating them is impure.

Roman




_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to