Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/Data/Array/Polarized/Push.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@
--
-- This module is designed to be imported qualified as @Push@.
module Data.Array.Polarized.Push
( Array(..)
, alloc
(
-- * Construction
Array(..)
, make
, singleton
, cons
, snoc
-- * Operations
, alloc
, foldMap
, unzip
)
where

Expand All @@ -22,7 +30,7 @@ import qualified Data.Array.Destination as DArray
import Data.Array.Destination (DArray)
import Data.Vector (Vector)
import qualified Prelude
import Prelude.Linear
import Prelude.Linear hiding (unzip, foldMap)
import GHC.Stack


Expand Down Expand Up @@ -66,6 +74,21 @@ make x n
| n < 0 = error "Making a negative length push array"
| otherwise = Array (\makeA -> mconcat $ Prelude.replicate n (makeA x))

singleton :: a -> Array a
singleton x = Array (\writeA -> writeA x)

snoc :: a -> Array a %1-> Array a
snoc x (Array k) = Array (\writeA -> (k writeA) <> (writeA x))

cons :: a -> Array a %1-> Array a
cons x (Array k) = Array (\writeA -> (writeA x) <> (k writeA))

foldMap :: Monoid b => (a -> b) -> Array a %1-> b
foldMap f (Array k) = k f

unzip :: Array (a,b) %1-> (Array a, Array b)
unzip (Array k) = k (\(a,b) -> (singleton a, singleton b))


-- # Instances
-------------------------------------------------------------------------------
Expand Down