{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Data.Array.Polarized.Pull
( Array
, fromFunction
, fromVector
, make
, singleton
, toVector
, asList
, zip
, zipWith
, append
, foldr
, foldMap
, findLength
, split
, reverse
, index
)
where
import Data.Array.Polarized.Pull.Internal
import qualified Data.Functor.Linear as Data
import Prelude.Linear hiding (zip, zipWith, foldr, foldMap, reverse)
import Data.Vector (Vector)
import qualified Data.Vector as Vector
import qualified Unsafe.Linear as Unsafe
asList :: Array a %1-> [a]
asList :: forall a. Array a %1 -> [a]
asList = (a %1 -> [a] %1 -> [a]) -> [a] %1 -> Array a %1 -> [a]
forall a b. (a %1 -> b %1 -> b) -> b %1 -> Array a %1 -> b
foldr (\a
x [a]
xs -> a
xa %1 -> [a] %1 -> [a]
forall a. a -> [a] -> [a]
:[a]
xs) []
zipWith :: (a %1-> b %1-> c) -> Array a %1-> Array b %1-> Array c
zipWith :: forall a b c.
(a %1 -> b %1 -> c) -> Array a %1 -> Array b %1 -> Array c
zipWith a %1 -> b %1 -> c
f Array a
x Array b
y = ((a, b) %1 -> c) -> Array (a, b) %1 -> Array c
forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Data.fmap ((a %1 -> b %1 -> c) %1 -> (a, b) %1 -> c
forall a b c. (a %1 -> b %1 -> c) %1 -> (a, b) %1 -> c
uncurry a %1 -> b %1 -> c
f) (Array a %1 -> Array b %1 -> Array (a, b)
forall a b. Array a %1 -> Array b %1 -> Array (a, b)
zip Array a
x Array b
y)
foldMap :: Monoid m => (a %1-> m) -> Array a %1-> m
foldMap :: forall m a. Monoid m => (a %1 -> m) -> Array a %1 -> m
foldMap a %1 -> m
f = (a %1 -> m %1 -> m) -> m %1 -> Array a %1 -> m
forall a b. (a %1 -> b %1 -> b) -> b %1 -> Array a %1 -> b
foldr (m %1 -> m %1 -> m
forall a. Semigroup a => a %1 -> a %1 -> a
(<>) (m %1 -> m %1 -> m) %1 -> (a %1 -> m) %1 -> a %1 -> m %1 -> m
forall b c a. (b %1 -> c) %1 -> (a %1 -> b) %1 -> a %1 -> c
. a %1 -> m
f) m
forall a. Monoid a => a
mempty
fromVector :: Vector a %1-> Array a
fromVector :: forall a. Vector a %1 -> Array a
fromVector = (Vector a -> Array a) %1 -> Vector a %1 -> Array a
forall a b (p :: Multiplicity). (a %p -> b) %1 -> a %1 -> b
Unsafe.toLinear ((Vector a -> Array a) %1 -> Vector a %1 -> Array a)
%1 -> (Vector a -> Array a) %1 -> Vector a %1 -> Array a
forall a b. (a %1 -> b) %1 -> a %1 -> b
$ \Vector a
v -> (Int -> a) -> Int -> Array a
forall a. (Int -> a) -> Int -> Array a
fromFunction (Vector a
v Vector a -> Int -> a
forall a. Vector a -> Int -> a
Vector.!) (Vector a -> Int
forall a. Vector a -> Int
Vector.length Vector a
v)