File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change 1111--
1212-- This module is designed to be imported qualified as @Push@.
1313module Data.Array.Polarized.Push
14- ( Array (.. )
15- , alloc
14+ (
15+ -- * Construction
16+ Array (.. )
1617 , make
18+ , singleton
19+ , cons
20+ , snoc
21+ -- * Operations
22+ , alloc
23+ , foldMap
24+ , unzip
1725 )
1826where
1927
@@ -22,7 +30,7 @@ import qualified Data.Array.Destination as DArray
2230import Data.Array.Destination (DArray )
2331import Data.Vector (Vector )
2432import qualified Prelude
25- import Prelude.Linear
33+ import Prelude.Linear hiding ( unzip , foldMap )
2634import GHC.Stack
2735
2836
@@ -66,6 +74,21 @@ make x n
6674 | n < 0 = error " Making a negative length push array"
6775 | otherwise = Array (\ makeA -> mconcat $ Prelude. replicate n (makeA x))
6876
77+ singleton :: a -> Array a
78+ singleton x = Array (\ writeA -> writeA x)
79+
80+ snoc :: a -> Array a % 1 -> Array a
81+ snoc x (Array k) = Array (\ writeA -> (k writeA) <> (writeA x))
82+
83+ cons :: a -> Array a % 1 -> Array a
84+ cons x (Array k) = Array (\ writeA -> (writeA x) <> (k writeA))
85+
86+ foldMap :: Monoid b => (a -> b ) -> Array a % 1 -> b
87+ foldMap f (Array k) = k f
88+
89+ unzip :: Array (a ,b ) % 1 -> (Array a , Array b )
90+ unzip (Array k) = k (\ (a,b) -> (singleton a, singleton b))
91+
6992
7093-- # Instances
7194-------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments