Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog.d/20260713_180352_st_clone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Fixed

- `Data.Array.ST` exports `clone` again: upstream v7.3.0 declares
`clone`/`cloneImpl` (`STFn1`), but the fork carried neither, so code using
`Data.Array.ST.clone` failed to compile against the fork. The Lua module
now provides `cloneImpl`, the same independent copy the FFI already uses
for `thawImpl`/`freezeImpl`.
1 change: 1 addition & 0 deletions src/Data/Array/ST.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ return {
unsafeThawImpl = (function(xs) return xs end),
freezeImpl = (copyImpl),
thawImpl = (copyImpl),
cloneImpl = (copyImpl),
sortByImpl = ((function()
local function rshift(x, by) return math.floor(x / 2 ^ by) end

Expand Down
10 changes: 10 additions & 0 deletions src/Data/Array/ST.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Data.Array.ST
, sortWith
, freeze
, thaw
, clone
, unsafeFreeze
, unsafeThaw
, toAssocArray
Expand Down Expand Up @@ -95,6 +96,15 @@ thaw = runSTFn1 thawImpl
-- | Create a mutable copy of an immutable array.
foreign import thawImpl :: forall h a. STFn1 (Array a) h (STArray h a)

-- | Make a mutable copy of a mutable array.
clone
:: forall h a
. STArray h a
-> ST h (STArray h a)
clone = runSTFn1 cloneImpl

foreign import cloneImpl :: forall h a. STFn1 (STArray h a) h (STArray h a)

-- | Sort a mutable array in place. Sorting is stable: the order of equal
-- | elements is preserved.
sort :: forall a h. Ord a => STArray h a -> ST h (STArray h a)
Expand Down
9 changes: 9 additions & 0 deletions test/regression/array_st.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ do
check("thawImpl is independent", copy[1] == 1, "copy mutated to " .. tostring(copy[1]))
end

-- cloneImpl (the same move-to-fresh-table path) is an independent copy.
do
local xs = {1, 2, 3}
local copy = ST.cloneImpl(xs)
checkArray("cloneImpl copies", copy, {1, 2, 3})
xs[1] = 99
check("cloneImpl is independent", copy[1] == 1, "copy mutated to " .. tostring(copy[1]))
end

-- toAssocArrayImpl builds zero-based {index, value} records.
do
local r = ST.toAssocArrayImpl({"a", "b"})
Expand Down