Skip to content

Commit 21d6dab

Browse files
fix off by one errors
1 parent 0e250b8 commit 21d6dab

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Data/Primitive/Vec.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ instance (KnownNat n, Prim a) => Vectoring (Vec n a) a where
110110
let n :: Int
111111
n = fromIntegral $ natVal $ Proxy @n
112112
mba <- newByteArray (n * sizeOf (undefined :: a))
113-
let new_vs = zipWith (\i' v' -> if i' == i then v else v') [0..n] (listOfVec vec)
114-
zipWithM_ (writeByteArray mba) [0..n] new_vs
113+
let new_vs = zipWith (\i' v' -> if i' == i then v else v') [0..n-1] (listOfVec vec)
114+
zipWithM_ (writeByteArray mba) [0..n-1] new_vs
115115
ByteArray nba# <- unsafeFreezeByteArray mba
116116
return $! Vec nba#
117117
vecEmpty = mkVec
@@ -139,7 +139,7 @@ vecOfList :: forall n a. (KnownNat n, Prim a) => [a] -> Vec n a
139139
vecOfList vs = runST $ do
140140
let n :: Int = fromIntegral $ natVal $ Proxy @n
141141
mba <- newByteArray (n * sizeOf (undefined :: a))
142-
zipWithM_ (writeByteArray mba) [0..n] vs
142+
zipWithM_ (writeByteArray mba) [0..n-1] vs
143143
ByteArray ba# <- unsafeFreezeByteArray mba
144144
return $! Vec ba#
145145

0 commit comments

Comments
 (0)