packages feed

hw-prim 0.6.2.20 → 0.6.2.21

raw patch · 2 files changed

+16/−1 lines, 2 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ HaskellWorks.Data.Vector.Storable: constructSI :: forall a s. Storable a => Int -> (Int -> s -> (s, a)) -> s -> (s, Vector a)

Files

hw-prim.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           hw-prim-version:        0.6.2.20+version:        0.6.2.21 synopsis:       Primitive functions and data types description:    Primitive functions and data types. category:       Data
src/HaskellWorks/Data/Vector/Storable.hs view
@@ -6,6 +6,7 @@   , foldMap   , mapAccumL   , mmap+  , constructSI   ) where  import Control.Monad.ST     (ST)@@ -54,3 +55,17 @@   (fptr :: ForeignPtr Word8, offset, size) <- IO.mmapFileForeignPtr filepath IO.ReadOnly Nothing   let !v = DVS.unsafeFromForeignPtr fptr offset size   return (DVS.unsafeCast v)++-- | Construct a vector statefully with index+constructSI :: forall a s. Storable a => Int -> (Int -> s -> (s, a)) -> s -> (s, DVS.Vector a)+constructSI n f state = DVS.createT $ do+  mv <- DVSM.unsafeNew n+  state' <- go 0 state mv+  return (state', mv)+  where go :: Int -> s -> DVSM.MVector t a -> ST t s+        go i s mv = if i < DVSM.length mv+          then do+            let (s', a) = f i s+            DVSM.unsafeWrite mv i a+            return s'+          else return s