Add new PrimArray constructor

This commit is contained in:
Kiana Sheibani 2022-05-13 08:26:51 -04:00
parent ad25af6e3f
commit a95f38202c
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -26,6 +26,13 @@ arrayDataSet : Nat -> a -> ArrayData a -> IO ()
arrayDataSet n x arr = fromPrim $ prim__arraySet arr (cast n) x
export
unsafeFromIns : Nat -> List (Nat, a) -> PrimArray a
unsafeFromIns size ins = unsafePerformIO $ do
arr <- newArrayData size (believe_me ())
for_ ins $ \(i,x) => arrayDataSet i x arr
pure $ MkPrimArray size arr
export
create : Nat -> (Nat -> a) -> PrimArray a
create size f = unsafePerformIO $ do
@ -40,7 +47,6 @@ create size f = unsafePerformIO $ do
addToArray (S loc) n arr
export
unsafeIndex : Nat -> PrimArray a -> a
unsafeIndex n arr = unsafePerformIO $ arrayDataGet n $ content arr