{-# 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 Data.Vector (Vector)
import qualified Data.Vector as Vector
import Prelude.Linear hiding (foldMap, foldr, reverse, zip, zipWith)
import qualified Unsafe.Linear as Unsafe
asList :: Array a %1 -> [a]
asList :: forall a. Array a %1 -> [a]
asList = forall a b. (a %1 -> b %1 -> b) -> b %1 -> Array a %1 -> b
foldr (\a
x [a]
xs -> a
x 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 = forall (f :: * -> *) a b. Functor f => (a %1 -> b) -> f a %1 -> f b
Data.fmap (forall a b c (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b %p -> c) %q -> (a, b) %p -> c
uncurry a %1 -> b %1 -> c
f) (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 = forall a b. (a %1 -> b %1 -> b) -> b %1 -> Array a %1 -> b
foldr (forall a. Semigroup a => a %1 -> a %1 -> a
(<>) forall b c a (q :: Multiplicity) (m :: Multiplicity)
(n :: Multiplicity).
(b %1 -> c) %q -> (a %1 -> b) %m -> a %n -> c
. a %1 -> m
f) forall a. Monoid a => a
mempty
fromVector :: Vector a %1 -> Array a
fromVector :: forall a. Vector a %1 -> Array a
fromVector = forall a b (p :: Multiplicity) (x :: Multiplicity).
(a %p -> b) %1 -> a %x -> b
Unsafe.toLinear forall a b (p :: Multiplicity) (q :: Multiplicity).
(a %p -> b) %q -> a %p -> b
$ \Vector a
v -> forall a. (Int -> a) -> Int -> Array a
fromFunction (Vector a
v forall a. Vector a -> Int -> a
Vector.!) (forall a. Vector a -> Int
Vector.length Vector a
v)