packages feed

primitive-unlifted 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+66/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Primitive.Unlifted.Array: foldlUnliftedArrayM' :: (PrimUnlifted a, Monad m) => (b -> a -> m b) -> b -> UnliftedArray a -> m b
+ Data.Primitive.Unlifted.Array: itraverseUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (Int -> a -> m b) -> UnliftedArray a -> m ()
+ Data.Primitive.Unlifted.Array: traverseUnliftedArray_ :: (PrimUnlifted a, Applicative m) => (a -> m b) -> UnliftedArray a -> m ()
+ Data.Primitive.Unlifted.Class: instance Data.Primitive.Unlifted.Class.PrimUnlifted (Data.Primitive.PrimArray.MutablePrimArray s a)
+ Data.Primitive.Unlifted.Class: instance Data.Primitive.Unlifted.Class.PrimUnlifted (Data.Primitive.PrimArray.PrimArray a)

Files

primitive-unlifted.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: primitive-unlifted-version: 0.1.0.0+version: 0.1.1.0 synopsis: Primitive GHC types with unlifted types inside homepage: https://github.com/andrewthad/primitive-unlifted bug-reports: https://github.com/andrewthad/primitive-unlifted/issues
src/Data/Primitive/Unlifted/Array.hs view
@@ -65,6 +65,10 @@   , foldrUnliftedArray'   , foldlUnliftedArray   , foldlUnliftedArray'+  , foldlUnliftedArrayM'+    -- * Traversals+  , traverseUnliftedArray_+  , itraverseUnliftedArray_     -- * Mapping   , mapUnliftedArray   ) where@@ -342,6 +346,41 @@     go !i !acc       | i < sz = go (i + 1) (f acc (indexUnliftedArray arr i))       | otherwise = acc++-- | Strict effectful left-associated fold over the elements of an 'UnliftedArray'.+{-# INLINE foldlUnliftedArrayM' #-}+foldlUnliftedArrayM' :: (PrimUnlifted a, Monad m)+  => (b -> a -> m b) -> b -> UnliftedArray a -> m b+foldlUnliftedArrayM' f z0 arr = go 0 z0+  where+    !sz = sizeofUnliftedArray arr+    go !i !acc+      | i < sz = f acc (indexUnliftedArray arr i) >>= go (i + 1) +      | otherwise = pure acc++-- | Effectfully traverse the elements of an 'UnliftedArray', discarding+-- the resulting values.+{-# INLINE traverseUnliftedArray_ #-}+traverseUnliftedArray_ :: (PrimUnlifted a, Applicative m)+  => (a -> m b) -> UnliftedArray a -> m ()+traverseUnliftedArray_ f arr = go 0+  where+    !sz = sizeofUnliftedArray arr+    go !i+      | i < sz = f (indexUnliftedArray arr i) *> go (i + 1) +      | otherwise = pure ()++-- | Effectful indexed traversal of the elements of an 'UnliftedArray',+-- discarding the resulting values.+{-# INLINE itraverseUnliftedArray_ #-}+itraverseUnliftedArray_ :: (PrimUnlifted a, Applicative m)+  => (Int -> a -> m b) -> UnliftedArray a -> m ()+itraverseUnliftedArray_ f arr = go 0+  where+    !sz = sizeofUnliftedArray arr+    go !i+      | i < sz = f i (indexUnliftedArray arr i) *> go (i + 1) +      | otherwise = pure ()  -- | Map over the elements of an 'UnliftedArray'. {-# INLINE mapUnliftedArray #-}
src/Data/Primitive/Unlifted/Class.hs view
@@ -6,6 +6,7 @@   ( PrimUnlifted(..)   ) where +import Data.Primitive.PrimArray (PrimArray(..),MutablePrimArray(..)) import Data.Primitive.ByteArray (ByteArray(..),MutableByteArray(..)) import GHC.Exts (State#,MutableByteArray#,ByteArray#,Int#) import GHC.Exts (ArrayArray#,MutableArrayArray#,RuntimeRep(UnliftedRep))@@ -33,6 +34,18 @@     -> Int#     -> a +instance PrimUnlifted (PrimArray a) where+  {-# inline writeUnliftedArray# #-}+  {-# inline readUnliftedArray# #-}+  {-# inline indexUnliftedArray# #-}+  type Unlifted (PrimArray a) = ByteArray#+  toUnlifted# (PrimArray x) = x+  fromUnlifted# x = PrimArray x+  writeUnliftedArray# a i (PrimArray x) = Exts.writeByteArrayArray# a i x+  readUnliftedArray# a i s0 = case Exts.readByteArrayArray# a i s0 of+    (# s1, x #) -> (# s1, PrimArray x #)+  indexUnliftedArray# a i = PrimArray (Exts.indexByteArrayArray# a i)+ instance PrimUnlifted ByteArray where   {-# inline writeUnliftedArray# #-}   {-# inline readUnliftedArray# #-}@@ -57,6 +70,19 @@   readUnliftedArray# a i s0 = case Exts.readMutableByteArrayArray# a i s0 of     (# s1, x #) -> (# s1, MutableByteArray (retoken x) #)   indexUnliftedArray# a i = MutableByteArray (baToMba (Exts.indexByteArrayArray# a i))++instance PrimUnlifted (MutablePrimArray s a) where+  {-# inline writeUnliftedArray# #-}+  {-# inline readUnliftedArray# #-}+  {-# inline indexUnliftedArray# #-}+  type Unlifted (MutablePrimArray s a) = MutableByteArray# s+  toUnlifted# (MutablePrimArray x) = x+  fromUnlifted# x = MutablePrimArray x+  writeUnliftedArray# a i (MutablePrimArray x) =+    Exts.writeMutableByteArrayArray# a i (retoken x)+  readUnliftedArray# a i s0 = case Exts.readMutableByteArrayArray# a i s0 of+    (# s1, x #) -> (# s1, MutablePrimArray (retoken x) #)+  indexUnliftedArray# a i = MutablePrimArray (baToMba (Exts.indexByteArrayArray# a i))  baToMba :: ByteArray# -> MutableByteArray# s {-# inline baToMba #-}