hdgarrood / purescript-sequences

Various efficient-ish sequence types for PureScript.
http://pursuit.purescript.org/packages/purescript-sequences
MIT License
45 stars 22 forks source link

Behaviour of Data.Sequence.replace #19

Closed rgrempel closed 8 years ago

rgrempel commented 8 years ago

I was a bit surprised by the behaviour of Data.Sequence.replace ... consider this:

let joe = Data.Sequence.toSeq [0, 1, 2, 3]
Data.Sequence.replace 24 2 joe

-- (toSeq [24,0,1,3])

It looks like replace removes the element specified by the index, but adds the new element at the beginning ... that is, when adding the new element, it ignores the index and just adds it at the start.

Is this a bug or a feature?

For my own purposes, I do need to work around it.

hdgarrood commented 8 years ago

That doesn't seem consistent with the docs. I think it is a bug, and the return value should be [0,1,24,3] — is that what you were expecting, too?

Given that the implementation is just replace x = adjust (const x), I think adjust might be broken in the same way.

rgrempel commented 8 years ago

Yes, that's what I expected as well.

As for the docs, I suppose it does "replace" the element in a way (in that it deletes the right element) -- I was just expecting it to replace it at the same position. :-)

hdgarrood commented 8 years ago

Given that an explicit order is one of the defining features of sequences, I think this is definitely wrong.

hdgarrood commented 8 years ago

Should be fixed in 0.4.3. Thanks for reporting! :)

rgrempel commented 8 years ago

Yes, I've tested 0.4.3 in my app, and it works as expected now.

Thanks -- that was fast!