When converting our mutable array to a vector (#205), we end up having a GHC.Exts.Array#. Which happens to be te same type Data.Vector.Vector is made of, but we can not use it since its constructor is hidden.
Instead, we have to go through a roundabaut way; from Array# to MutableArray# to MVector to Vector; all using some kind of unsafe calls.
|
-- | /O(1)/ Convert an 'Array' to an immutable 'Vector.Vector' (from |
|
-- 'vector' package). |
|
freeze :: Array a #-> Ur (Vector.Vector a) |
|
freeze (Array arr) = |
|
Unlifted.freeze go arr |
|
where |
|
go arr = unsafeDupablePerformIO $ do |
|
mut <- Prim.unsafeThawArray (Prim.Array arr) |
|
let mv = MVector.MVector 0 (Prim.sizeofMutableArray mut) mut |
|
Vector.unsafeFreeze mv |
|
-- We only need to do above because 'Vector' constructor is hidden. |
|
-- Once it is exposed, we should be able to replace it with something |
|
-- safer like: `go arr = Vector 0 (sizeof arr) arr` |
Making Vector's constructor visible would solve this easily, so we should consider contributing upstream.
Related upstream issue: haskell/vector#171
When converting our mutable array to a vector (#205), we end up having a
GHC.Exts.Array#. Which happens to be te same typeData.Vector.Vectoris made of, but we can not use it since its constructor is hidden.Instead, we have to go through a roundabaut way; from
Array#toMutableArray#toMVectortoVector; all using some kind of unsafe calls.linear-base/src/Data/Array/Mutable/Linear.hs
Lines 223 to 235 in c4fec0e
Making
Vector's constructor visible would solve this easily, so we should consider contributing upstream.Related upstream issue: haskell/vector#171