@@ -66,7 +66,8 @@ module Data.Vector.Strict.Mutable (
66
66
67
67
-- ** Filling and copying
68
68
set , copy , move , unsafeCopy , unsafeMove ,
69
-
69
+ -- ** Lazy arrays
70
+ toLazy , fromLazy , lazyFromLazy ,
70
71
-- ** Arrays
71
72
fromMutableArray , toMutableArray ,
72
73
@@ -707,6 +708,31 @@ ifoldrM' :: (PrimMonad m) => (Int -> a -> b -> m b) -> b -> MVector (PrimState m
707
708
{-# INLINE ifoldrM' #-}
708
709
ifoldrM' = G. ifoldrM'
709
710
711
+ -- Conversions - Lazy vectors
712
+ -- -----------------------------
713
+
714
+ -- | /O(1)/ Convert strict mutable vector to lazy mutable
715
+ -- vector. Vectors will share mutable buffer
716
+ toLazy :: MVector s a -> MV. MVector s a
717
+ {-# INLINE toLazy #-}
718
+ toLazy (MVector vec) = vec
719
+
720
+ -- | /O(1)/ Convert lazy mutable vector to strict mutable
721
+ -- vector. Vectors will share mutable buffer. This function does not
722
+ -- evaluate vector elements to WHNF.
723
+ lazyFromLazy :: MV. MVector s a -> MVector s a
724
+ {-# INLINE lazyFromLazy #-}
725
+ lazyFromLazy = MVector
726
+
727
+ -- | /O(1)/ Convert lazy mutable vector to strict mutable
728
+ -- vector. Vectors will share mutable buffer. This function evaluates
729
+ -- vector elements to WHNF.
730
+ fromLazy :: PrimMonad m => MV. MVector (PrimState m ) a -> m (MVector (PrimState m ) a )
731
+ fromLazy mvec = stToPrim $ do
732
+ G. foldM' (\ _ ! _ -> return () ) () mvec
733
+ return $ MVector mvec
734
+
735
+
710
736
-- Conversions - Arrays
711
737
-- -----------------------------
712
738
0 commit comments