module UVMHS.Core.Vector
  ( module UVMHS.Core.Vector
  , module Foreign.Storable
  ) where

import UVMHS.Core.Init
import UVMHS.Core.Monads ()

import UVMHS.Core.Classes
import UVMHS.Core.Data
import UVMHS.Core.Sized

import Foreign.Storable (Storable(..))

import qualified Prelude as HS
import qualified Data.Vector as VB
import qualified Data.Vector.Mutable as VBM
import qualified Data.Vector.Storable as VU

-------
-- 𝕍 --
-------

newtype 𝕍 a = 𝕍 { forall a. 𝕍 a -> Vector a
un𝕍  VB.Vector a }
  deriving (𝕍 a -> 𝕍 a -> Bool
(𝕍 a -> 𝕍 a -> Bool) -> (𝕍 a -> 𝕍 a -> Bool) -> Eq (𝕍 a)
forall a. Eq a => 𝕍 a -> 𝕍 a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => 𝕍 a -> 𝕍 a -> Bool
== :: 𝕍 a -> 𝕍 a -> Bool
$c/= :: forall a. Eq a => 𝕍 a -> 𝕍 a -> Bool
/= :: 𝕍 a -> 𝕍 a -> Bool
Eq,Eq (𝕍 a)
Eq (𝕍 a) =>
(𝕍 a -> 𝕍 a -> Ordering)
-> (𝕍 a -> 𝕍 a -> Bool)
-> (𝕍 a -> 𝕍 a -> Bool)
-> (𝕍 a -> 𝕍 a -> Bool)
-> (𝕍 a -> 𝕍 a -> Bool)
-> (𝕍 a -> 𝕍 a -> 𝕍 a)
-> (𝕍 a -> 𝕍 a -> 𝕍 a)
-> Ord (𝕍 a)
𝕍 a -> 𝕍 a -> Bool
𝕍 a -> 𝕍 a -> Ordering
𝕍 a -> 𝕍 a -> 𝕍 a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (𝕍 a)
forall a. Ord a => 𝕍 a -> 𝕍 a -> Bool
forall a. Ord a => 𝕍 a -> 𝕍 a -> Ordering
forall a. Ord a => 𝕍 a -> 𝕍 a -> 𝕍 a
$ccompare :: forall a. Ord a => 𝕍 a -> 𝕍 a -> Ordering
compare :: 𝕍 a -> 𝕍 a -> Ordering
$c< :: forall a. Ord a => 𝕍 a -> 𝕍 a -> Bool
< :: 𝕍 a -> 𝕍 a -> Bool
$c<= :: forall a. Ord a => 𝕍 a -> 𝕍 a -> Bool
<= :: 𝕍 a -> 𝕍 a -> Bool
$c> :: forall a. Ord a => 𝕍 a -> 𝕍 a -> Bool
> :: 𝕍 a -> 𝕍 a -> Bool
$c>= :: forall a. Ord a => 𝕍 a -> 𝕍 a -> Bool
>= :: 𝕍 a -> 𝕍 a -> Bool
$cmax :: forall a. Ord a => 𝕍 a -> 𝕍 a -> 𝕍 a
max :: 𝕍 a -> 𝕍 a -> 𝕍 a
$cmin :: forall a. Ord a => 𝕍 a -> 𝕍 a -> 𝕍 a
min :: 𝕍 a -> 𝕍 a -> 𝕍 a
Ord)

instance            ToIter a (𝕍 a)     where iter :: 𝕍 a -> 𝐼 a
iter  = 𝕍 a -> 𝐼 a
forall a. 𝕍 a -> 𝐼 a
iter𝕍
instance (Show a)  Show (𝕍 a)         where show :: 𝕍 a -> String
show  = 𝕊 -> String
tohsChars (𝕊 -> String) -> (𝕍 a -> 𝕊) -> 𝕍 a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕍 a -> 𝕊
forall a. Show a => 𝕍 a -> 𝕊
show𝕍
instance            Lookup ℕ64 a (𝕍 a) where ⋕? :: 𝕍 a -> ℕ64 -> 𝑂 a
(⋕?)  = (ℕ64 -> 𝕍 a -> 𝑂 a) -> 𝕍 a -> ℕ64 -> 𝑂 a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ℕ64 -> 𝕍 a -> 𝑂 a
forall a. ℕ64 -> 𝕍 a -> 𝑂 a
idx𝕍
instance            Functor 𝕍          where map :: forall a b. (a -> b) -> 𝕍 a -> 𝕍 b
map   = (a -> b) -> 𝕍 a -> 𝕍 b
forall a b. (a -> b) -> 𝕍 a -> 𝕍 b
map𝕍
instance            FunctorM 𝕍         where mapM :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> 𝕍 a -> m (𝕍 b)
mapM  = (a -> m b) -> 𝕍 a -> m (𝕍 b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> 𝕍 a -> m (𝕍 b)
mapM𝕍
instance            CSized (𝕍 a)       where csize :: 𝕍 a -> ℕ64
csize = 𝕍 a -> ℕ64
forall a. 𝕍 a -> ℕ64
csize𝕍
instance            Single a (𝕍 a)     where single :: a -> 𝕍 a
single = a -> 𝕍 a
forall a. a -> 𝕍 a
single𝕍
instance            Null (𝕍 a)         where null :: 𝕍 a
null  = 𝕍 a
forall a. 𝕍 a
null𝕍
instance            Append (𝕍 a)       where ⧺ :: 𝕍 a -> 𝕍 a -> 𝕍 a
(⧺)   = 𝕍 a -> 𝕍 a -> 𝕍 a
forall a. 𝕍 a -> 𝕍 a -> 𝕍 a
append𝕍
instance            Monoid (𝕍 a)

instance ToIterC a (𝕍 a) where
  iterC :: 𝕍 a -> 𝐼C a
iterC 𝕍 a
xs = ℕ64 -> 𝐼 a -> 𝐼C a
forall a. ℕ64 -> 𝐼 a -> 𝐼C a
𝐼C (𝕍 a -> ℕ64
forall a. CSized a => a -> ℕ64
csize 𝕍 a
xs) (𝐼 a -> 𝐼C a) -> 𝐼 a -> 𝐼C a
forall a b. (a -> b) -> a -> b
$ 𝕍 a -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter 𝕍 a
xs

vec  (ToIter a t)  t  𝕍 a
vec :: forall a t. ToIter a t => t -> 𝕍 a
vec = Vector a -> 𝕍 a
forall a. Vector a -> 𝕍 a
𝕍 (Vector a -> 𝕍 a) -> ([a] -> Vector a) -> [a] -> 𝕍 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 [a] -> Vector a
forall a. [a] -> Vector a
VB.fromList ([a] -> 𝕍 a) -> (t -> [a]) -> t -> 𝕍 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 t -> [a]
forall a t. ToIter a t => t -> [a]
lazyList

vecC  (ToIterC a t)  t  𝕍 a
vecC :: forall a t. ToIterC a t => t -> 𝕍 a
vecC t
xs =
  let xsi :: 𝐼C a
xsi = t -> 𝐼C a
forall a t. ToIterC a t => t -> 𝐼C a
iterC t
xs
  in Vector a -> 𝕍 a
forall a. Vector a -> 𝕍 a
𝕍 (Vector a -> 𝕍 a) -> Vector a -> 𝕍 a
forall a b. (a -> b) -> a -> b
$ Int -> [a] -> Vector a
forall a. Int -> [a] -> Vector a
VB.fromListN (ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℤ64 -> Int) -> ℤ64 -> Int
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 (ℕ64 -> ℤ64) -> ℕ64 -> ℤ64
forall a b. (a -> b) -> a -> b
$ 𝐼C a -> ℕ64
forall a. CSized a => a -> ℕ64
csize 𝐼C a
xsi) ([a] -> Vector a) -> [a] -> Vector a
forall a b. (a -> b) -> a -> b
$ 𝐼C a -> [a]
forall a t. ToIter a t => t -> [a]
lazyList 𝐼C a
xsi

vecF  ℕ64  (ℕ64  a)  𝕍 a
vecF :: forall a. ℕ64 -> (ℕ64 -> a) -> 𝕍 a
vecF ℕ64
n ℕ64 -> a
f = 𝐼C a -> 𝕍 a
forall a t. ToIterC a t => t -> 𝕍 a
vecC (𝐼C a -> 𝕍 a) -> 𝐼C a -> 𝕍 a
forall a b. (a -> b) -> a -> b
$ (ℕ64 -> a) -> 𝐼C ℕ64 -> 𝐼C a
forall a b. (a -> b) -> 𝐼C a -> 𝐼C b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ℕ64 -> a
f (𝐼C ℕ64 -> 𝐼C a) -> 𝐼C ℕ64 -> 𝐼C a
forall a b. (a -> b) -> a -> b
$ ℕ64 -> 𝐼C ℕ64
uptoC ℕ64
n

vecDΩ  ℕ64  a  𝕍 a
vecDΩ :: forall a. (ℕ64 ⇰ a) -> 𝕍 a
vecDΩ ℕ64 ⇰ a
d = case (ℕ64 ⇰ a) -> 𝑂 ℕ64
forall k a. (k ⇰ a) -> 𝑂 k
dmaxKey𝐷 ℕ64 ⇰ a
d of
  𝑂 ℕ64
None  𝐼 a -> 𝕍 a
forall a t. ToIter a t => t -> 𝕍 a
vec 𝐼 a
forall a. 𝐼 a
empty𝐼
  Some ℕ64
k  ℕ64 -> (ℕ64 -> a) -> 𝕍 a
forall a. ℕ64 -> (ℕ64 -> a) -> 𝕍 a
vecF (ℕ64
k ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
forall a. One a => a
one) ((ℕ64 -> a) -> 𝕍 a) -> (ℕ64 -> a) -> 𝕍 a
forall a b. (a -> b) -> a -> b
$ \ ℕ64
n  ℕ64 ⇰ a
d (ℕ64 ⇰ a) -> ℕ64 -> a
forall k v t. (Lookup k v t, STACK) => t -> k -> v
⋕! ℕ64
n

iter𝕍  𝕍 a  𝐼 a
iter𝕍 :: forall a. 𝕍 a -> 𝐼 a
iter𝕍 𝕍 a
xs = [a] -> 𝐼 a
forall a. [a] -> 𝐼 a
iterLL ([a] -> 𝐼 a) -> [a] -> 𝐼 a
forall a b. (a -> b) -> a -> b
$ Vector a -> [a]
forall a. Vector a -> [a]
VB.toList (Vector a -> [a]) -> Vector a -> [a]
forall a b. (a -> b) -> a -> b
$ 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍 𝕍 a
xs

show𝕍  (Show a)  𝕍 a  𝕊
show𝕍 :: forall a. Show a => 𝕍 a -> 𝕊
show𝕍 = 𝕊 -> 𝕊 -> 𝕊 -> (a -> 𝕊) -> 𝐼 a -> 𝕊
forall a t. ToIter a t => 𝕊 -> 𝕊 -> 𝕊 -> (a -> 𝕊) -> t -> 𝕊
showCollection 𝕊
"𝕍[" 𝕊
"]" 𝕊
"," a -> 𝕊
forall a. Show a => a -> 𝕊
show𝕊 (𝐼 a -> 𝕊) -> (𝕍 a -> 𝐼 a) -> 𝕍 a -> 𝕊
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕍 a -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter

idx𝕍  ℕ64  𝕍 a  𝑂 a
idx𝕍 :: forall a. ℕ64 -> 𝕍 a -> 𝑂 a
idx𝕍 ℕ64
i 𝕍 a
xs = Maybe a -> 𝑂 a
forall a b. CHS a b => b -> a
frhs (Maybe a -> 𝑂 a) -> Maybe a -> 𝑂 a
forall a b. (a -> b) -> a -> b
$ 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍 𝕍 a
xs Vector a -> Int -> Maybe a
forall a. Vector a -> Int -> Maybe a
VB.!? ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i)

idx𝕍Ω  ℕ64  𝕍 a  a
idx𝕍Ω :: forall a. ℕ64 -> 𝕍 a -> a
idx𝕍Ω ℕ64
i 𝕍 a
xs = 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍 𝕍 a
xs Vector a -> Int -> a
forall a. Vector a -> Int -> a
VB.! ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i)

idx𝕍Ω_UNSAFE  ℕ64  𝕍 a  a
idx𝕍Ω_UNSAFE :: forall a. ℕ64 -> 𝕍 a -> a
idx𝕍Ω_UNSAFE ℕ64
i 𝕍 a
xs = 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍 𝕍 a
xs Vector a -> Int -> a
forall a. Vector a -> Int -> a
`VB.unsafeIndex` ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i)

map𝕍  (a  b)  𝕍 a  𝕍 b
map𝕍 :: forall a b. (a -> b) -> 𝕍 a -> 𝕍 b
map𝕍 a -> b
f = Vector b -> 𝕍 b
forall a. Vector a -> 𝕍 a
𝕍 (Vector b -> 𝕍 b) -> (Vector a -> Vector b) -> Vector a -> 𝕍 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (a -> b) -> Vector a -> Vector b
forall a b. (a -> b) -> Vector a -> Vector b
VB.map a -> b
f (Vector a -> 𝕍 b) -> (𝕍 a -> Vector a) -> 𝕍 a -> 𝕍 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍

mapM𝕍   m a b. (Monad m)  (a  m b)  𝕍 a  m (𝕍 b)
mapM𝕍 :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> 𝕍 a -> m (𝕍 b)
mapM𝕍 a -> m b
f = W (Monad m) -> (Monad m => 𝕍 a -> m (𝕍 b)) -> 𝕍 a -> m (𝕍 b)
forall (c :: Constraint) a. W c -> (c => a) -> a
with (forall (m :: * -> *). Monad m => W (Monad m)
tohsMonad @m) ((Monad m => 𝕍 a -> m (𝕍 b)) -> 𝕍 a -> m (𝕍 b))
-> (Monad m => 𝕍 a -> m (𝕍 b)) -> 𝕍 a -> m (𝕍 b)
forall a b. (a -> b) -> a -> b
HS.$ Vector b -> 𝕍 b
forall a. Vector a -> 𝕍 a
𝕍 (Vector b -> 𝕍 b)
-> (Vector a -> m (Vector b)) -> Vector a -> m (𝕍 b)
forall (t :: * -> *) b c a.
Functor t =>
(b -> c) -> (a -> t b) -> a -> t c
^∘ (a -> m b) -> Vector a -> m (Vector b)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Vector a -> m (Vector b)
VB.mapM a -> m b
f (Vector a -> m (𝕍 b)) -> (𝕍 a -> Vector a) -> 𝕍 a -> m (𝕍 b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍

nulls𝕍  (Null a)  ℕ64  𝕍 a
nulls𝕍 :: forall a. Null a => ℕ64 -> 𝕍 a
nulls𝕍 ℕ64
n = ℕ64 -> (ℕ64 -> a) -> 𝕍 a
forall a. ℕ64 -> (ℕ64 -> a) -> 𝕍 a
vecF ℕ64
n ((ℕ64 -> a) -> 𝕍 a) -> (ℕ64 -> a) -> 𝕍 a
forall a b. (a -> b) -> a -> b
$ a -> ℕ64 -> a
forall a b. a -> b -> a
const a
forall a. Null a => a
null

csize𝕍  𝕍 a  ℕ64
csize𝕍 :: forall a. 𝕍 a -> ℕ64
csize𝕍 = ℤ64 -> ℕ64
forall a. (ToNatO64 a, STACK) => a -> ℕ64
natΩ64 (ℤ64 -> ℕ64) -> (Int -> ℤ64) -> Int -> ℕ64
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Int -> ℤ64
forall a b. CHS a b => b -> a
frhs (Int -> ℕ64) -> (Vector a -> Int) -> Vector a -> ℕ64
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Vector a -> Int
forall a. Vector a -> Int
VB.length (Vector a -> ℕ64) -> (𝕍 a -> Vector a) -> 𝕍 a -> ℕ64
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍

null𝕍  𝕍 a
null𝕍 :: forall a. 𝕍 a
null𝕍 = [a] -> 𝕍 a
forall a t. ToIter a t => t -> 𝕍 a
vec []

append𝕍  𝕍 a  𝕍 a  𝕍 a
append𝕍 :: forall a. 𝕍 a -> 𝕍 a -> 𝕍 a
append𝕍 𝕍 a
xs 𝕍 a
ys = Vector a -> 𝕍 a
forall a. Vector a -> 𝕍 a
𝕍 (Vector a -> 𝕍 a) -> Vector a -> 𝕍 a
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector a -> Vector a
forall a. Vector a -> Vector a -> Vector a
(VB.++) (𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍 𝕍 a
xs) (Vector a -> Vector a) -> Vector a -> Vector a
forall a b. (a -> b) -> a -> b
$ 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍 𝕍 a
ys

single𝕍  a  𝕍 a
single𝕍 :: forall a. a -> 𝕍 a
single𝕍 = Vector a -> 𝕍 a
forall a. Vector a -> 𝕍 a
𝕍 (Vector a -> 𝕍 a) -> (a -> Vector a) -> a -> 𝕍 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 a -> Vector a
forall a. a -> Vector a
VB.singleton

----------
--- 𝕍M ---
----------

newtype 𝕍Mut a = 𝕍Mut { forall a. 𝕍Mut a -> IOVector a
un𝕍Mut  VBM.IOVector a }

vecIMut  (ToIter a t)  t  IO (𝕍Mut a)
vecIMut :: forall a t. ToIter a t => t -> IO (𝕍Mut a)
vecIMut t
xs = do
  let n :: ℤ64
n = t -> ℤ64
forall n t a. (Zero n, One n, Plus n, ToIter a t) => t -> n
count t
xs
  IOVector a
v  Int -> IO (MVector (PrimState IO) a)
forall (m :: * -> *) a.
PrimMonad m =>
Int -> m (MVector (PrimState m) a)
VBM.new (Int -> IO (MVector (PrimState IO) a))
-> Int -> IO (MVector (PrimState IO) a)
forall a b. (a -> b) -> a -> b
$ ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs ℤ64
n
  𝐼 (ℤ64 ∧ a) -> ((ℤ64 ∧ a) -> IO ()) -> IO ()
forall (m :: * -> *) a t.
(Monad m, ToIter a t) =>
t -> (a -> m ()) -> m ()
eachOn (t -> 𝐼 (ℤ64 ∧ a)
forall n t a. (Zero n, One n, Plus n, ToIter a t) => t -> 𝐼 (n ∧ a)
withIndex t
xs) (((ℤ64 ∧ a) -> IO ()) -> IO ()) -> ((ℤ64 ∧ a) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ (ℤ64
i :* a
x)  MVector (PrimState IO) a -> Int -> a -> IO ()
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> a -> m ()
VBM.write IOVector a
MVector (PrimState IO) a
v (ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs ℤ64
i) a
x
  𝕍Mut a -> IO (𝕍Mut a)
forall a. a -> IO a
forall (m :: * -> *) a. Return m => a -> m a
return (𝕍Mut a -> IO (𝕍Mut a)) -> 𝕍Mut a -> IO (𝕍Mut a)
forall a b. (a -> b) -> a -> b
$ IOVector a -> 𝕍Mut a
forall a. IOVector a -> 𝕍Mut a
𝕍Mut IOVector a
v

vecVMut  𝕍 a  IO (𝕍Mut a)
vecVMut :: forall a. 𝕍 a -> IO (𝕍Mut a)
vecVMut 𝕍 a
v = IOVector a -> 𝕍Mut a
forall a. IOVector a -> 𝕍Mut a
𝕍Mut (IOVector a -> 𝕍Mut a) -> IO (IOVector a) -> IO (𝕍Mut a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ Vector a -> IO (MVector (PrimState IO) a)
forall (m :: * -> *) a.
PrimMonad m =>
Vector a -> m (MVector (PrimState m) a)
VB.thaw (Vector a -> IO (MVector (PrimState IO) a))
-> Vector a -> IO (MVector (PrimState IO) a)
forall a b. (a -> b) -> a -> b
$ 𝕍 a -> Vector a
forall a. 𝕍 a -> Vector a
un𝕍 𝕍 a
v

idx𝕍Mut  ℕ64  𝕍Mut a  IO a
idx𝕍Mut :: forall a. ℕ64 -> 𝕍Mut a -> IO a
idx𝕍Mut ℕ64
i 𝕍Mut a
v = do
  a
x  MVector (PrimState IO) a -> Int -> IO a
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> m a
VBM.read (𝕍Mut a -> IOVector a
forall a. 𝕍Mut a -> IOVector a
un𝕍Mut 𝕍Mut a
v) (Int -> IO a) -> Int -> IO a
forall a b. (a -> b) -> a -> b
$ ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℤ64 -> Int) -> ℤ64 -> Int
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i
  a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Return m => a -> m a
return (a -> IO a) -> a -> IO a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a b. CHS a b => b -> a
frhs a
x

set𝕍Mut  ℕ64  a  𝕍Mut a  IO ()
set𝕍Mut :: forall a. ℕ64 -> a -> 𝕍Mut a -> IO ()
set𝕍Mut ℕ64
i a
x 𝕍Mut a
v = do
  MVector (PrimState IO) a -> Int -> a -> IO ()
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> a -> m ()
VBM.write (𝕍Mut a -> IOVector a
forall a. 𝕍Mut a -> IOVector a
un𝕍Mut 𝕍Mut a
v) (ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℤ64 -> Int) -> ℤ64 -> Int
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i) a
x

eachI𝕍Mut  (ℕ64  a  IO ())  𝕍Mut a  IO ()
eachI𝕍Mut :: forall a. (ℕ64 -> a -> IO ()) -> 𝕍Mut a -> IO ()
eachI𝕍Mut ℕ64 -> a -> IO ()
f = (Int -> a -> IO ()) -> MVector (PrimState IO) a -> IO ()
forall (m :: * -> *) a b.
PrimMonad m =>
(Int -> a -> m b) -> MVector (PrimState m) a -> m ()
VBM.imapM_ (\ Int
i  ℕ64 -> a -> IO ()
f (ℕ64 -> a -> IO ()) -> ℕ64 -> a -> IO ()
forall a b. (a -> b) -> a -> b
$ ℤ64 -> ℕ64
forall a. (ToNatO64 a, STACK) => a -> ℕ64
natΩ64 (ℤ64 -> ℕ64) -> ℤ64 -> ℕ64
forall a b. (a -> b) -> a -> b
$ Int -> ℤ64
forall a b. CHS a b => b -> a
frhs Int
i) (MVector (PrimState IO) a -> IO ())
-> (𝕍Mut a -> MVector (PrimState IO) a) -> 𝕍Mut a -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕍Mut a -> IOVector a
𝕍Mut a -> MVector (PrimState IO) a
forall a. 𝕍Mut a -> IOVector a
un𝕍Mut

each𝕍Mut  (a  IO ())  𝕍Mut a  IO ()
each𝕍Mut :: forall a. (a -> IO ()) -> 𝕍Mut a -> IO ()
each𝕍Mut = (ℕ64 -> a -> IO ()) -> 𝕍Mut a -> IO ()
forall a. (ℕ64 -> a -> IO ()) -> 𝕍Mut a -> IO ()
eachI𝕍Mut ((ℕ64 -> a -> IO ()) -> 𝕍Mut a -> IO ())
-> ((a -> IO ()) -> ℕ64 -> a -> IO ())
-> (a -> IO ())
-> 𝕍Mut a
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (a -> IO ()) -> ℕ64 -> a -> IO ()
forall a b. a -> b -> a
const

values𝕍Mut  𝕍Mut a  IO (𝕍 a)
values𝕍Mut :: forall a. 𝕍Mut a -> IO (𝕍 a)
values𝕍Mut 𝕍Mut a
v = Vector a -> 𝕍 a
forall a. Vector a -> 𝕍 a
𝕍 (Vector a -> 𝕍 a) -> IO (Vector a) -> IO (𝕍 a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ MVector (PrimState IO) a -> IO (Vector a)
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> m (Vector a)
VB.freeze (MVector (PrimState IO) a -> IO (Vector a))
-> MVector (PrimState IO) a -> IO (Vector a)
forall a b. (a -> b) -> a -> b
$ 𝕍Mut a -> IOVector a
forall a. 𝕍Mut a -> IOVector a
un𝕍Mut 𝕍Mut a
v

grow𝕍Mut  ℕ64  𝕍Mut a  IO (𝕍Mut a)
grow𝕍Mut :: forall a. ℕ64 -> 𝕍Mut a -> IO (𝕍Mut a)
grow𝕍Mut ℕ64
i 𝕍Mut a
v = IOVector a -> 𝕍Mut a
forall a. IOVector a -> 𝕍Mut a
𝕍Mut (IOVector a -> 𝕍Mut a) -> IO (IOVector a) -> IO (𝕍Mut a)
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
^$ MVector (PrimState IO) a -> Int -> IO (MVector (PrimState IO) a)
forall (m :: * -> *) a.
PrimMonad m =>
MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
VBM.grow (𝕍Mut a -> IOVector a
forall a. 𝕍Mut a -> IOVector a
un𝕍Mut 𝕍Mut a
v) (Int -> IO (MVector (PrimState IO) a))
-> Int -> IO (MVector (PrimState IO) a)
forall a b. (a -> b) -> a -> b
$ ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℤ64 -> Int) -> ℤ64 -> Int
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i

{-

instance ToStream a (𝕍 a)      where stream = stream𝕍
instance ToIter a (𝕍 a)        where iter   = iter ∘ stream
instance (Show a) ⇒ Show (𝕍 a) where show   = tohsChars ∘ show𝕍
instance Lookup ℕ64 a (𝕍 a)    where (⋕?)   = flip idx𝕍
instance Functor 𝕍             where map    = map𝕍
instance FunctorM 𝕍            where mapM   = mapM𝕍

vec ∷ (ToIter a t) ⇒ t → 𝕍 a
vec = 𝕍 ∘ VB.fromList ∘ lazyList

vecC ∷ (ToIterC a t) ⇒ t → 𝕍 a
vecC xs =
  let xsi = iterC xs
  in 𝕍 $ VB.fromListN (tohs $ intΩ64 $ csize xsi) $ lazyList xsi

vecF ∷ ℕ64 → (ℕ64 → a) → 𝕍 a
vecF n f = vecC $ map f $ upToC n

vecDΩ ∷ ℕ64 ⇰ a → 𝕍 a
vecDΩ d = case dmaxKey d of
  None → vec empty𝐼
  Some k → vecF (k + one) $ \ n → d ⋕! n

stream𝕍 ∷ 𝕍 a → 𝑆 a
stream𝕍 xs = stream $ VB.toList $ un𝕍 xs

show𝕍 ∷ (Show a) ⇒ 𝕍 a → 𝕊
show𝕍 = showCollection "𝕍[" "]" "," show𝕊 ∘ iter

idx𝕍 ∷ ℕ64 → 𝕍 a → 𝑂 a
idx𝕍 i xs = frhs $ un𝕍 xs VB.!? tohs (intΩ64 i)

idx𝕍Ω ∷ ℕ64 → 𝕍 a → a
idx𝕍Ω i xs = un𝕍 xs VB.! tohs (intΩ64 i)

idx𝕍Ω_UNSAFE ∷ ℕ64 → 𝕍 a → a
idx𝕍Ω_UNSAFE i xs = un𝕍 xs `VB.unsafeIndex` tohs (intΩ64 i)

map𝕍 ∷ (a → b) → 𝕍 a → 𝕍 b
map𝕍 f = 𝕍 ∘ VB.map f ∘ un𝕍

mapM𝕍 ∷ ∀ m a b. (Monad m) ⇒ (a → m b) → 𝕍 a → m (𝕍 b)
mapM𝕍 f = with (tohsMonad @m) $ 𝕍 ^∘ VB.mapM f ∘ un𝕍

null𝕍 ∷ (Null a) ⇒ ℕ64 → 𝕍 a
null𝕍 n = vecF n $ const null
-}

-------
-- 𝕌 --
-------

newtype 𝕌 a = 𝕌 { forall a. 𝕌 a -> Vector a
un𝕌  VU.Vector a }
  deriving (𝕌 a -> 𝕌 a -> Bool
(𝕌 a -> 𝕌 a -> Bool) -> (𝕌 a -> 𝕌 a -> Bool) -> Eq (𝕌 a)
forall a. (Storable a, Eq a) => 𝕌 a -> 𝕌 a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. (Storable a, Eq a) => 𝕌 a -> 𝕌 a -> Bool
== :: 𝕌 a -> 𝕌 a -> Bool
$c/= :: forall a. (Storable a, Eq a) => 𝕌 a -> 𝕌 a -> Bool
/= :: 𝕌 a -> 𝕌 a -> Bool
Eq,Eq (𝕌 a)
Eq (𝕌 a) =>
(𝕌 a -> 𝕌 a -> Ordering)
-> (𝕌 a -> 𝕌 a -> Bool)
-> (𝕌 a -> 𝕌 a -> Bool)
-> (𝕌 a -> 𝕌 a -> Bool)
-> (𝕌 a -> 𝕌 a -> Bool)
-> (𝕌 a -> 𝕌 a -> 𝕌 a)
-> (𝕌 a -> 𝕌 a -> 𝕌 a)
-> Ord (𝕌 a)
𝕌 a -> 𝕌 a -> Bool
𝕌 a -> 𝕌 a -> Ordering
𝕌 a -> 𝕌 a -> 𝕌 a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. (Storable a, Ord a) => Eq (𝕌 a)
forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> Bool
forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> Ordering
forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> 𝕌 a
$ccompare :: forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> Ordering
compare :: 𝕌 a -> 𝕌 a -> Ordering
$c< :: forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> Bool
< :: 𝕌 a -> 𝕌 a -> Bool
$c<= :: forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> Bool
<= :: 𝕌 a -> 𝕌 a -> Bool
$c> :: forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> Bool
> :: 𝕌 a -> 𝕌 a -> Bool
$c>= :: forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> Bool
>= :: 𝕌 a -> 𝕌 a -> Bool
$cmax :: forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> 𝕌 a
max :: 𝕌 a -> 𝕌 a -> 𝕌 a
$cmin :: forall a. (Storable a, Ord a) => 𝕌 a -> 𝕌 a -> 𝕌 a
min :: 𝕌 a -> 𝕌 a -> 𝕌 a
Ord)

instance (Storable a)  ToIter a (𝕌 a)     where iter :: 𝕌 a -> 𝐼 a
iter   = 𝕌 a -> 𝐼 a
forall a. Storable a => 𝕌 a -> 𝐼 a
iter𝕌
instance (Storable a,Show a)  Show (𝕌 a)  where show :: 𝕌 a -> String
show   = 𝕊 -> String
tohsChars (𝕊 -> String) -> (𝕌 a -> 𝕊) -> 𝕌 a -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕌 a -> 𝕊
forall a. (Storable a, Show a) => 𝕌 a -> 𝕊
show𝕌
instance (Storable a)  Lookup ℕ64 a (𝕌 a) where ⋕? :: 𝕌 a -> ℕ64 -> 𝑂 a
(⋕?)   = (ℕ64 -> 𝕌 a -> 𝑂 a) -> 𝕌 a -> ℕ64 -> 𝑂 a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ℕ64 -> 𝕌 a -> 𝑂 a
forall a. Storable a => ℕ64 -> 𝕌 a -> 𝑂 a
idx𝕌

instance (Storable a)  CSized    (𝕌 a) where csize :: 𝕌 a -> ℕ64
csize = 𝕌 a -> ℕ64
forall a. Storable a => 𝕌 a -> ℕ64
csize𝕌
instance (Storable a)  ToIterC a (𝕌 a) where iterC :: 𝕌 a -> 𝐼C a
iterC 𝕌 a
xs = ℕ64 -> 𝐼 a -> 𝐼C a
forall a. ℕ64 -> 𝐼 a -> 𝐼C a
𝐼C (𝕌 a -> ℕ64
forall a. CSized a => a -> ℕ64
csize 𝕌 a
xs) (𝐼 a -> 𝐼C a) -> 𝐼 a -> 𝐼C a
forall a b. (a -> b) -> a -> b
$ 𝕌 a -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter 𝕌 a
xs

instance (Storable a,Join a)  Join (𝕌 a) where ⊔ :: 𝕌 a -> 𝕌 a -> 𝕌 a
(⊔) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. Join a => a -> a -> a
(⊔)
instance (Storable a,Meet a)  Meet (𝕌 a) where ⊓ :: 𝕌 a -> 𝕌 a -> 𝕌 a
(⊓) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. Meet a => a -> a -> a
(⊓)
instance (Storable a,Plus a)  Plus (𝕌 a) where + :: 𝕌 a -> 𝕌 a -> 𝕌 a
(+) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. Plus a => a -> a -> a
(+)
instance (Storable a,Minus a)  Minus (𝕌 a) where (-) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 (-)
instance (Storable a,Times a)  Times (𝕌 a) where × :: 𝕌 a -> 𝕌 a -> 𝕌 a
(×) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. Times a => a -> a -> a
(×)
instance (Storable a,Divide a)  Divide (𝕌 a) where / :: 𝕌 a -> 𝕌 a -> 𝕌 a
(/) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. Divide a => a -> a -> a
(/)
instance (Storable a,DivMod a)  DivMod (𝕌 a) where {⌿ :: 𝕌 a -> 𝕌 a -> 𝕌 a
(⌿) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. DivMod a => a -> a -> a
(⌿);÷ :: 𝕌 a -> 𝕌 a -> 𝕌 a
(÷) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. DivMod a => a -> a -> a
(÷)}
instance (Storable a,Pow a)  Pow (𝕌 a) where ^ :: 𝕌 a -> 𝕌 a -> 𝕌 a
(^) = (a -> a -> a) -> 𝕌 a -> 𝕌 a -> 𝕌 a
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> a -> a
forall a. Pow a => a -> a -> a
(^)
instance (Storable a,Pon a)  Pon (𝕌 a) where 𝕌 a
xs ^^ :: 𝕌 a -> ℕ -> 𝕌 a
^^ y = (a -> a) -> 𝕌 a -> 𝕌 a
forall a b. (Storable a, Storable b) => (a -> b) -> 𝕌 a -> 𝕌 b
map𝕌 (a -> ℕ -> a
forall a. Pon a => a -> ℕ -> a
^^ y) 𝕌 a
xs

instance (Storable a,Root a)  Root (𝕌 a) where root :: 𝕌 a -> 𝕌 a
root = (a -> a) -> 𝕌 a -> 𝕌 a
forall a b. (Storable a, Storable b) => (a -> b) -> 𝕌 a -> 𝕌 b
map𝕌 a -> a
forall a. Root a => a -> a
root

uvec  (Storable a,ToIter a t)  t  𝕌 a
uvec :: forall a t. (Storable a, ToIter a t) => t -> 𝕌 a
uvec = Vector a -> 𝕌 a
forall a. Vector a -> 𝕌 a
𝕌 (Vector a -> 𝕌 a) -> ([a] -> Vector a) -> [a] -> 𝕌 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 [a] -> Vector a
forall a. Storable a => [a] -> Vector a
VU.fromList ([a] -> 𝕌 a) -> (t -> [a]) -> t -> 𝕌 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
 t -> [a]
forall a t. ToIter a t => t -> [a]
lazyList

uvecC  (Storable a,ToIterC a t)  t  𝕌 a
uvecC :: forall a t. (Storable a, ToIterC a t) => t -> 𝕌 a
uvecC t
xs =
  let xsi :: 𝐼C a
xsi = t -> 𝐼C a
forall a t. ToIterC a t => t -> 𝐼C a
iterC t
xs
  in Vector a -> 𝕌 a
forall a. Vector a -> 𝕌 a
𝕌 (Vector a -> 𝕌 a) -> Vector a -> 𝕌 a
forall a b. (a -> b) -> a -> b
$ Int -> [a] -> Vector a
forall a. Storable a => Int -> [a] -> Vector a
VU.fromListN (ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℤ64 -> Int) -> ℤ64 -> Int
forall a b. (a -> b) -> a -> b
$ ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 (ℕ64 -> ℤ64) -> ℕ64 -> ℤ64
forall a b. (a -> b) -> a -> b
$ 𝐼C a -> ℕ64
forall a. CSized a => a -> ℕ64
csize 𝐼C a
xsi) ([a] -> Vector a) -> [a] -> Vector a
forall a b. (a -> b) -> a -> b
$ 𝐼C a -> [a]
forall a t. ToIter a t => t -> [a]
lazyList 𝐼C a
xsi

uvecF  (Storable a)  ℕ64  (ℕ64  a)  𝕌 a
uvecF :: forall a. Storable a => ℕ64 -> (ℕ64 -> a) -> 𝕌 a
uvecF ℕ64
n ℕ64 -> a
f = 𝐼 a -> 𝕌 a
forall a t. (Storable a, ToIter a t) => t -> 𝕌 a
uvec (𝐼 a -> 𝕌 a) -> 𝐼 a -> 𝕌 a
forall a b. (a -> b) -> a -> b
$ (ℕ64 -> a) -> 𝐼 ℕ64 -> 𝐼 a
forall a b. (a -> b) -> 𝐼 a -> 𝐼 b
forall (t :: * -> *) a b. Functor t => (a -> b) -> t a -> t b
map ℕ64 -> a
f (𝐼 ℕ64 -> 𝐼 a) -> 𝐼 ℕ64 -> 𝐼 a
forall a b. (a -> b) -> a -> b
$ ℕ64 -> 𝐼 ℕ64
forall n. (Eq n, Zero n, One n, Plus n) => n -> 𝐼 n
upto ℕ64
n

uvecDΩ  (Storable a)  ℕ64  a  𝕌 a
uvecDΩ :: forall a. Storable a => (ℕ64 ⇰ a) -> 𝕌 a
uvecDΩ ℕ64 ⇰ a
d = case (ℕ64 ⇰ a) -> 𝑂 ℕ64
forall k a. (k ⇰ a) -> 𝑂 k
dmaxKey𝐷 ℕ64 ⇰ a
d of
  𝑂 ℕ64
None  𝐼 a -> 𝕌 a
forall a t. (Storable a, ToIter a t) => t -> 𝕌 a
uvec 𝐼 a
forall a. 𝐼 a
empty𝐼
  Some ℕ64
k  ℕ64 -> (ℕ64 -> a) -> 𝕌 a
forall a. Storable a => ℕ64 -> (ℕ64 -> a) -> 𝕌 a
uvecF (ℕ64
k ℕ64 -> ℕ64 -> ℕ64
forall a. Plus a => a -> a -> a
+ ℕ64
forall a. One a => a
one) ((ℕ64 -> a) -> 𝕌 a) -> (ℕ64 -> a) -> 𝕌 a
forall a b. (a -> b) -> a -> b
$ \ ℕ64
n  ℕ64 ⇰ a
d (ℕ64 ⇰ a) -> ℕ64 -> a
forall k v t. (Lookup k v t, STACK) => t -> k -> v
⋕! ℕ64
n

iter𝕌  (Storable a)  𝕌 a  𝐼 a
iter𝕌 :: forall a. Storable a => 𝕌 a -> 𝐼 a
iter𝕌 𝕌 a
xs = [a] -> 𝐼 a
forall a. [a] -> 𝐼 a
iterLL ([a] -> 𝐼 a) -> [a] -> 𝐼 a
forall a b. (a -> b) -> a -> b
$ Vector a -> [a]
forall a. Storable a => Vector a -> [a]
VU.toList (Vector a -> [a]) -> Vector a -> [a]
forall a b. (a -> b) -> a -> b
$ 𝕌 a -> Vector a
forall a. 𝕌 a -> Vector a
un𝕌 𝕌 a
xs

show𝕌  (Storable a,Show a)  𝕌 a  𝕊
show𝕌 :: forall a. (Storable a, Show a) => 𝕌 a -> 𝕊
show𝕌 = 𝕊 -> 𝕊 -> 𝕊 -> (a -> 𝕊) -> 𝐼 a -> 𝕊
forall a t. ToIter a t => 𝕊 -> 𝕊 -> 𝕊 -> (a -> 𝕊) -> t -> 𝕊
showCollection 𝕊
"𝕌[" 𝕊
"]" 𝕊
"," a -> 𝕊
forall a. Show a => a -> 𝕊
show𝕊 (𝐼 a -> 𝕊) -> (𝕌 a -> 𝐼 a) -> 𝕌 a -> 𝕊
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕌 a -> 𝐼 a
forall a t. ToIter a t => t -> 𝐼 a
iter

csize𝕌  (Storable a)  𝕌 a  ℕ64
csize𝕌 :: forall a. Storable a => 𝕌 a -> ℕ64
csize𝕌 = ℤ64 -> ℕ64
forall a. (ToNatO64 a, STACK) => a -> ℕ64
natΩ64 (ℤ64 -> ℕ64) -> (Int -> ℤ64) -> Int -> ℕ64
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Int -> ℤ64
forall a b. CHS a b => b -> a
frhs (Int -> ℕ64) -> (Vector a -> Int) -> Vector a -> ℕ64
forall b c a. (b -> c) -> (a -> b) -> a -> c
 Vector a -> Int
forall a. Storable a => Vector a -> Int
VU.length (Vector a -> ℕ64) -> (𝕌 a -> Vector a) -> 𝕌 a -> ℕ64
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕌 a -> Vector a
forall a. 𝕌 a -> Vector a
un𝕌

idx𝕌  (Storable a)  ℕ64  𝕌 a  𝑂 a
idx𝕌 :: forall a. Storable a => ℕ64 -> 𝕌 a -> 𝑂 a
idx𝕌 ℕ64
i 𝕌 a
xs = Maybe a -> 𝑂 a
forall a b. CHS a b => b -> a
frhs (Maybe a -> 𝑂 a) -> Maybe a -> 𝑂 a
forall a b. (a -> b) -> a -> b
$ 𝕌 a -> Vector a
forall a. 𝕌 a -> Vector a
un𝕌 𝕌 a
xs Vector a -> Int -> Maybe a
forall a. Storable a => Vector a -> Int -> Maybe a
VU.!? ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i)

idx𝕌Ω  (Storable a)  ℕ64  𝕌 a  a
idx𝕌Ω :: forall a. Storable a => ℕ64 -> 𝕌 a -> a
idx𝕌Ω ℕ64
i 𝕌 a
xs = a -> a
forall a b. CHS a b => b -> a
frhs (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ 𝕌 a -> Vector a
forall a. 𝕌 a -> Vector a
un𝕌 𝕌 a
xs Vector a -> Int -> a
forall a. Storable a => Vector a -> Int -> a
VU.! ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i)

idx𝕌Ω_UNSAFE  (Storable a)  ℕ64  𝕌 a  a
idx𝕌Ω_UNSAFE :: forall a. Storable a => ℕ64 -> 𝕌 a -> a
idx𝕌Ω_UNSAFE ℕ64
i 𝕌 a
xs = a -> a
forall a b. CHS a b => b -> a
frhs (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ 𝕌 a -> Vector a
forall a. 𝕌 a -> Vector a
un𝕌 𝕌 a
xs Vector a -> Int -> a
forall a. Storable a => Vector a -> Int -> a
`VU.unsafeIndex` ℤ64 -> Int
forall a b. CHS a b => a -> b
tohs (ℕ64 -> ℤ64
forall a. (ToIntO64 a, STACK) => a -> ℤ64
intΩ64 ℕ64
i)

map𝕌  (Storable a,Storable b)  (a  b)  𝕌 a  𝕌 b
map𝕌 :: forall a b. (Storable a, Storable b) => (a -> b) -> 𝕌 a -> 𝕌 b
map𝕌 a -> b
f = Vector b -> 𝕌 b
forall a. Vector a -> 𝕌 a
𝕌 (Vector b -> 𝕌 b) -> (Vector a -> Vector b) -> Vector a -> 𝕌 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 (a -> b) -> Vector a -> Vector b
forall a b.
(Storable a, Storable b) =>
(a -> b) -> Vector a -> Vector b
VU.map a -> b
f (Vector a -> 𝕌 b) -> (𝕌 a -> Vector a) -> 𝕌 a -> 𝕌 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕌 a -> Vector a
forall a. 𝕌 a -> Vector a
un𝕌

mapM𝕌   m a b. (Monad m,Storable a,Storable b)  (a  m b)  𝕌 a  m (𝕌 b)
mapM𝕌 :: forall (m :: * -> *) a b.
(Monad m, Storable a, Storable b) =>
(a -> m b) -> 𝕌 a -> m (𝕌 b)
mapM𝕌 a -> m b
f = W (Monad m) -> (Monad m => 𝕌 a -> m (𝕌 b)) -> 𝕌 a -> m (𝕌 b)
forall (c :: Constraint) a. W c -> (c => a) -> a
with (forall (m :: * -> *). Monad m => W (Monad m)
tohsMonad @m) ((Monad m => 𝕌 a -> m (𝕌 b)) -> 𝕌 a -> m (𝕌 b))
-> (Monad m => 𝕌 a -> m (𝕌 b)) -> 𝕌 a -> m (𝕌 b)
forall a b. (a -> b) -> a -> b
HS.$ Vector b -> 𝕌 b
forall a. Vector a -> 𝕌 a
𝕌 (Vector b -> 𝕌 b)
-> (Vector a -> m (Vector b)) -> Vector a -> m (𝕌 b)
forall (t :: * -> *) b c a.
Functor t =>
(b -> c) -> (a -> t b) -> a -> t c
^∘ (a -> m b) -> Vector a -> m (Vector b)
forall (m :: * -> *) a b.
(Monad m, Storable a, Storable b) =>
(a -> m b) -> Vector a -> m (Vector b)
VU.mapM a -> m b
f (Vector a -> m (𝕌 b)) -> (𝕌 a -> Vector a) -> 𝕌 a -> m (𝕌 b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
 𝕌 a -> Vector a
forall a. 𝕌 a -> Vector a
un𝕌

null𝕌  (Storable a,Null a)  ℕ64  𝕌 a
null𝕌 :: forall a. (Storable a, Null a) => ℕ64 -> 𝕌 a
null𝕌 ℕ64
n = ℕ64 -> (ℕ64 -> a) -> 𝕌 a
forall a. Storable a => ℕ64 -> (ℕ64 -> a) -> 𝕌 a
uvecF ℕ64
n ((ℕ64 -> a) -> 𝕌 a) -> (ℕ64 -> a) -> 𝕌 a
forall a b. (a -> b) -> a -> b
$ a -> ℕ64 -> a
forall a b. a -> b -> a
const a
forall a. Null a => a
null

zipWith𝕌  (Storable a,Storable b,Storable c)  (a  b  c)  𝕌 a  𝕌 b  𝕌 c
zipWith𝕌 :: forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌 a -> b -> c
f (𝕌 Vector a
xs) (𝕌 Vector b
ys) = Vector c -> 𝕌 c
forall a. Vector a -> 𝕌 a
𝕌 (Vector c -> 𝕌 c) -> Vector c -> 𝕌 c
forall a b. (a -> b) -> a -> b
$ (a -> b -> c) -> Vector a -> Vector b -> Vector c
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> Vector a -> Vector b -> Vector c
VU.zipWith a -> b -> c
f Vector a
xs Vector b
ys

zipWithOn𝕌  (Storable a,Storable b,Storable c)  𝕌 a  𝕌 b  (a  b  c)  𝕌 c
zipWithOn𝕌 :: forall a b c.
(Storable a, Storable b, Storable c) =>
𝕌 a -> 𝕌 b -> (a -> b -> c) -> 𝕌 c
zipWithOn𝕌 = ((a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c)
-> 𝕌 a -> 𝕌 b -> (a -> b -> c) -> 𝕌 c
forall a b c d. (a -> b -> c -> d) -> b -> c -> a -> d
rotateL (a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
forall a b c.
(Storable a, Storable b, Storable c) =>
(a -> b -> c) -> 𝕌 a -> 𝕌 b -> 𝕌 c
zipWith𝕌