Skip to content

Commit

Permalink
fix off by one errors
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoPeters1024 committed Dec 13, 2021
1 parent 0e250b8 commit 21d6dab
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Data/Primitive/Vec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ instance (KnownNat n, Prim a) => Vectoring (Vec n a) a where
let n :: Int
n = fromIntegral $ natVal $ Proxy @n
mba <- newByteArray (n * sizeOf (undefined :: a))
let new_vs = zipWith (\i' v' -> if i' == i then v else v') [0..n] (listOfVec vec)
zipWithM_ (writeByteArray mba) [0..n] new_vs
let new_vs = zipWith (\i' v' -> if i' == i then v else v') [0..n-1] (listOfVec vec)
zipWithM_ (writeByteArray mba) [0..n-1] new_vs
ByteArray nba# <- unsafeFreezeByteArray mba
return $! Vec nba#
vecEmpty = mkVec
Expand Down Expand Up @@ -139,7 +139,7 @@ vecOfList :: forall n a. (KnownNat n, Prim a) => [a] -> Vec n a
vecOfList vs = runST $ do
let n :: Int = fromIntegral $ natVal $ Proxy @n
mba <- newByteArray (n * sizeOf (undefined :: a))
zipWithM_ (writeByteArray mba) [0..n] vs
zipWithM_ (writeByteArray mba) [0..n-1] vs
ByteArray ba# <- unsafeFreezeByteArray mba
return $! Vec ba#

Expand Down

0 comments on commit 21d6dab

Please sign in to comment.