primitive-extras 0.6.2.1 → 0.6.3
raw patch · 3 files changed
+30/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ PrimitiveExtras.PrimArray: elementsFoldM :: Prim a => Int -> FoldM IO a (PrimArray a)
Files
- library/PrimitiveExtras/FoldMs.hs +20/−0
- library/PrimitiveExtras/PrimArray.hs +8/−0
- primitive-extras.cabal +2/−1
+ library/PrimitiveExtras/FoldMs.hs view
@@ -0,0 +1,20 @@+module PrimitiveExtras.FoldMs+where++import PrimitiveExtras.Prelude hiding (fold, foldM)+import PrimitiveExtras.Types+import Control.Foldl+import qualified PrimitiveExtras.UnliftedArray as UA+++{-|+Given a size of the array,+construct a fold, which produces an array of elements.+-}+primArray :: Prim a => Int {-^ Array size -} -> FoldM IO a (PrimArray a)+primArray size = FoldM step init extract where+ init = Product2 0 <$> newPrimArray size+ step (Product2 index mutable) a = do+ writePrimArray mutable index a+ return (Product2 (succ index) mutable)+ extract (Product2 _ mutable) = unsafeFreezePrimArray mutable
library/PrimitiveExtras/PrimArray.hs view
@@ -7,6 +7,7 @@ import qualified Data.Vector.Unboxed as UnboxedVector import qualified Data.Vector.Primitive as PrimitiveVector import qualified PrimitiveExtras.Folds as Folds+import qualified PrimitiveExtras.FoldMs as FoldMs oneHot :: Prim a => Int {-^ Size -} -> Int {-^ Index -} -> a -> PrimArray a@@ -107,3 +108,10 @@ -} indexCountsFold :: (Integral count, Prim count) => Int {-^ Array size -} -> Fold Int (PrimArray count) indexCountsFold = Folds.indexCounts++{-|+Given a size of the array,+construct a fold, which produces an array of elements.+-}+elementsFoldM :: Prim a => Int {-^ Array size -} -> FoldM IO a (PrimArray a)+elementsFoldM = FoldMs.primArray
primitive-extras.cabal view
@@ -1,7 +1,7 @@ name: primitive-extras version:- 0.6.2.1+ 0.6.3 category: Primitive synopsis:@@ -50,6 +50,7 @@ PrimitiveExtras.Prelude PrimitiveExtras.Types PrimitiveExtras.Folds+ PrimitiveExtras.FoldMs build-depends: base >=4.7 && <5, cereal >=0.5.5 && <0.6,