Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Vector.Fixed.Cont
Description
API for Church-encoded vectors. Implementation of function from Data.Vector.Fixed module uses these function internally in order to provide shortcut fusion.
Synopsis
- data PeanoNum
- type N1 = 'S 'Z
- type N2 = 'S N1
- type N3 = 'S N2
- type N4 = 'S N3
- type N5 = 'S N4
- type N6 = 'S N5
- type N7 = 'S N6
- type N8 = 'S N7
- type family Peano (n :: Nat) :: PeanoNum where ...
- type family Add (n :: PeanoNum) (m :: PeanoNum) :: PeanoNum where ...
- type family Fn (n :: PeanoNum) a b where ...
- newtype Fun (n :: PeanoNum) a b = Fun {}
- type Arity (n :: Nat) = ArityPeano (Peano n)
- class ArityPeano (n :: PeanoNum) where
- accum :: (forall (k :: PeanoNum). t ('S k) -> a -> t k) -> (t 'Z -> b) -> t n -> Fun n a b
- accumPeano :: (forall (k :: PeanoNum). ArityPeano k => t ('S k) -> a -> t k) -> (t 'Z -> b) -> t n -> Fun n a b
- applyFun :: (forall (k :: PeanoNum). t ('S k) -> (a, t k)) -> t n -> (ContVec n a, t 'Z)
- applyFunM :: Applicative f => (forall (k :: PeanoNum). t ('S k) -> (f a, t k)) -> t n -> (f (ContVec n a), t 'Z)
- reducePeano :: (forall (k :: PeanoNum). t ('S k) -> t k) -> t n -> t 'Z
- peanoToInt :: Proxy# n -> Int
- dictionaryPred :: forall (k :: PeanoNum) r. n ~ 'S k => Proxy# n -> (ArityPeano k => r) -> r
- apply :: forall (n :: PeanoNum) t a. ArityPeano n => (forall (k :: PeanoNum). t ('S k) -> (a, t k)) -> t n -> ContVec n a
- applyM :: forall f (n :: PeanoNum) t a. (Applicative f, ArityPeano n) => (forall (k :: PeanoNum). t ('S k) -> (f a, t k)) -> t n -> f (ContVec n a)
- class Index (k :: PeanoNum) (n :: PeanoNum) where
- constFun :: forall (n :: PeanoNum) a b. Fun n a b -> Fun ('S n) a b
- curryFirst :: forall (n :: PeanoNum) a b. Fun ('S n) a b -> a -> Fun n a b
- uncurryFirst :: forall a (n :: PeanoNum) b. (a -> Fun n a b) -> Fun ('S n) a b
- curryLast :: forall (n :: PeanoNum) a b. ArityPeano n => Fun ('S n) a b -> Fun n a (a -> b)
- curryMany :: forall (n :: PeanoNum) (k :: PeanoNum) a b. ArityPeano n => Fun (Add n k) a b -> Fun n a (Fun k a b)
- apLast :: forall (n :: PeanoNum) a b. ArityPeano n => Fun ('S n) a b -> a -> Fun n a b
- shuffleFun :: forall (n :: PeanoNum) b a r. ArityPeano n => (b -> Fun n a r) -> Fun n a (b -> r)
- withFun :: forall (n :: PeanoNum) a b c. (Fun n a b -> Fun n a c) -> Fun ('S n) a b -> Fun ('S n) a c
- dimapFun :: forall (n :: PeanoNum) a b c d. ArityPeano n => (a -> b) -> (c -> d) -> Fun n b c -> Fun n a d
- type family Dim (v :: Type -> Type) :: PeanoNum
- class ArityPeano (Dim v) => Vector (v :: Type -> Type) a where
- length :: ArityPeano (Dim v) => v a -> Int
- newtype ContVec (n :: PeanoNum) a = ContVec (forall r. Fun n a r -> r)
- consPeano :: forall a (n :: PeanoNum). a -> ContVec n a -> ContVec ('S n) a
- runContVec :: forall (n :: PeanoNum) a r. Fun n a r -> ContVec n a -> r
- cvec :: Vector v a => v a -> ContVec (Dim v) a
- fromList :: forall (n :: PeanoNum) a. ArityPeano n => [a] -> ContVec n a
- fromList' :: forall (n :: PeanoNum) a. ArityPeano n => [a] -> ContVec n a
- fromListM :: forall (n :: PeanoNum) a. ArityPeano n => [a] -> Maybe (ContVec n a)
- toList :: forall (n :: PeanoNum) a. ArityPeano n => ContVec n a -> [a]
- replicate :: forall (n :: PeanoNum) a. ArityPeano n => a -> ContVec n a
- replicateM :: forall (n :: PeanoNum) f a. (ArityPeano n, Applicative f) => f a -> f (ContVec n a)
- generate :: forall (n :: PeanoNum) a. ArityPeano n => (Int -> a) -> ContVec n a
- generateM :: forall f (n :: PeanoNum) a. (Applicative f, ArityPeano n) => (Int -> f a) -> f (ContVec n a)
- unfoldr :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> (a, b)) -> b -> ContVec n a
- basis :: forall a (n :: PeanoNum). (Num a, ArityPeano n) => Int -> ContVec n a
- empty :: ContVec 'Z a
- cons :: forall a (n :: PeanoNum). a -> ContVec n a -> ContVec ('S n) a
- consV :: forall (n :: PeanoNum) a. ArityPeano n => ContVec N1 a -> ContVec n a -> ContVec ('S n) a
- snoc :: forall (n :: PeanoNum) a. ArityPeano n => a -> ContVec n a -> ContVec ('S n) a
- concat :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, ArityPeano k, ArityPeano (Add n k)) => ContVec n a -> ContVec k a -> ContVec (Add n k) a
- mk1 :: a -> ContVec N1 a
- mk2 :: a -> a -> ContVec N2 a
- mk3 :: a -> a -> a -> ContVec N3 a
- mk4 :: a -> a -> a -> a -> ContVec N4 a
- mk5 :: a -> a -> a -> a -> a -> ContVec N5 a
- mk6 :: a -> a -> a -> a -> a -> a -> ContVec N6 a
- mk7 :: a -> a -> a -> a -> a -> a -> a -> ContVec N7 a
- mk8 :: a -> a -> a -> a -> a -> a -> a -> a -> ContVec N8 a
- map :: forall (n :: PeanoNum) a b. ArityPeano n => (a -> b) -> ContVec n a -> ContVec n b
- imap :: forall (n :: PeanoNum) a b. ArityPeano n => (Int -> a -> b) -> ContVec n a -> ContVec n b
- mapM :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (a -> f b) -> ContVec n a -> f (ContVec n b)
- imapM :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (Int -> a -> f b) -> ContVec n a -> f (ContVec n b)
- mapM_ :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (a -> f b) -> ContVec n a -> f ()
- imapM_ :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (Int -> a -> f b) -> ContVec n a -> f ()
- scanl :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> a -> b) -> b -> ContVec n a -> ContVec ('S n) b
- scanl1 :: forall (n :: PeanoNum) a. ArityPeano n => (a -> a -> a) -> ContVec n a -> ContVec n a
- sequence :: forall (n :: PeanoNum) f a. (ArityPeano n, Applicative f) => ContVec n (f a) -> f (ContVec n a)
- sequence_ :: forall (n :: PeanoNum) f a. (ArityPeano n, Applicative f) => ContVec n (f a) -> f ()
- distribute :: forall f (n :: PeanoNum) a. (Functor f, ArityPeano n) => f (ContVec n a) -> ContVec n (f a)
- collect :: forall f (n :: PeanoNum) a b. (Functor f, ArityPeano n) => (a -> ContVec n b) -> f a -> ContVec n (f b)
- tail :: forall (n :: PeanoNum) a. ContVec ('S n) a -> ContVec n a
- reverse :: forall (n :: PeanoNum) a. ArityPeano n => ContVec n a -> ContVec n a
- zipWith :: forall (n :: PeanoNum) a b c. ArityPeano n => (a -> b -> c) -> ContVec n a -> ContVec n b -> ContVec n c
- zipWith3 :: forall (n :: PeanoNum) a b c d. ArityPeano n => (a -> b -> c -> d) -> ContVec n a -> ContVec n b -> ContVec n c -> ContVec n d
- izipWith :: forall (n :: PeanoNum) a b c. ArityPeano n => (Int -> a -> b -> c) -> ContVec n a -> ContVec n b -> ContVec n c
- izipWith3 :: forall (n :: PeanoNum) a b c d. ArityPeano n => (Int -> a -> b -> c -> d) -> ContVec n a -> ContVec n b -> ContVec n c -> ContVec n d
- zipWithM :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (a -> b -> f c) -> ContVec n a -> ContVec n b -> f (ContVec n c)
- zipWithM_ :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (a -> b -> f c) -> ContVec n a -> ContVec n b -> f ()
- izipWithM :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (Int -> a -> b -> f c) -> ContVec n a -> ContVec n b -> f (ContVec n c)
- izipWithM_ :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (Int -> a -> b -> f c) -> ContVec n a -> ContVec n b -> f ()
- head :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, n ~ 'S k) => ContVec n a -> a
- index :: forall (n :: PeanoNum) a. ArityPeano n => Int -> ContVec n a -> a
- element :: forall (n :: PeanoNum) f a. (ArityPeano n, Functor f) => Int -> (a -> f a) -> ContVec n a -> f (ContVec n a)
- vector :: Vector v a => ContVec (Dim v) a -> v a
- foldl :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> a -> b) -> b -> ContVec n a -> b
- foldl' :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> a -> b) -> b -> ContVec n a -> b
- foldl1 :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, n ~ 'S k) => (a -> a -> a) -> ContVec n a -> a
- foldl1' :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, n ~ 'S k) => (a -> a -> a) -> ContVec n a -> a
- foldr :: forall (n :: PeanoNum) a b. ArityPeano n => (a -> b -> b) -> b -> ContVec n a -> b
- ifoldl :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> Int -> a -> b) -> b -> ContVec n a -> b
- ifoldl' :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> Int -> a -> b) -> b -> ContVec n a -> b
- ifoldr :: forall (n :: PeanoNum) a b. ArityPeano n => (Int -> a -> b -> b) -> b -> ContVec n a -> b
- foldM :: forall (n :: PeanoNum) m b a. (ArityPeano n, Monad m) => (b -> a -> m b) -> b -> ContVec n a -> m b
- ifoldM :: forall (n :: PeanoNum) m b a. (ArityPeano n, Monad m) => (b -> Int -> a -> m b) -> b -> ContVec n a -> m b
- sum :: forall a (n :: PeanoNum). (Num a, ArityPeano n) => ContVec n a -> a
- minimum :: forall a (n :: PeanoNum) (k :: PeanoNum). (Ord a, ArityPeano n, n ~ 'S k) => ContVec n a -> a
- maximum :: forall a (n :: PeanoNum) (k :: PeanoNum). (Ord a, ArityPeano n, n ~ 'S k) => ContVec n a -> a
- and :: forall (n :: PeanoNum). ArityPeano n => ContVec n Bool -> Bool
- or :: forall (n :: PeanoNum). ArityPeano n => ContVec n Bool -> Bool
- all :: forall (n :: PeanoNum) a. ArityPeano n => (a -> Bool) -> ContVec n a -> Bool
- any :: forall (n :: PeanoNum) a. ArityPeano n => (a -> Bool) -> ContVec n a -> Bool
- find :: forall (n :: PeanoNum) a. ArityPeano n => (a -> Bool) -> ContVec n a -> Maybe a
- gfoldl :: forall c v a. (Vector v a, Data a) => (forall x y. Data x => c (x -> y) -> x -> c y) -> (forall x. x -> c x) -> v a -> c (v a)
- gunfold :: forall con c v a. (Vector v a, Data a) => (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> con -> c (v a)
Type-level numbers
Peano numbers. Since type level naturals don't support induction we have to convert type nats to Peano representation first and work with it,
type family Peano (n :: Nat) :: PeanoNum where ... Source #
Convert type level natural to Peano representation
type family Add (n :: PeanoNum) (m :: PeanoNum) :: PeanoNum where ... Source #
Type family for sum of unary natural numbers.
N-ary functions
type family Fn (n :: PeanoNum) a b where ... Source #
Type family for n-ary functions. n
is number of parameters of
type a
and b
is result type.
newtype Fun (n :: PeanoNum) a b Source #
Newtype wrapper which is used to make Fn
injective. It's a
function which takes n
parameters of type a
and returns value
of type b
.
Instances
ArityPeano n => Applicative (Fun n a) Source # | |
ArityPeano n => Functor (Fun n a) Source # | |
ArityPeano n => Monad (Fun n a) Source # | Reader |
type Arity (n :: Nat) = ArityPeano (Peano n) Source #
Synonym for writing constrains using type level naturals.
class ArityPeano (n :: PeanoNum) where Source #
Type class for defining and applying n-ary functions.
Methods
Arguments
:: (forall (k :: PeanoNum). t ('S k) -> a -> t k) | Fold function |
-> (t 'Z -> b) | Extract result of fold |
-> t n | Initial value |
-> Fun n a b | Reduction function |
Left fold over n elements exposed as n-ary function. These elements are supplied as arguments to the function.
Arguments
:: (forall (k :: PeanoNum). ArityPeano k => t ('S k) -> a -> t k) | Fold function |
-> (t 'Z -> b) | Extract result of fold |
-> t n | Initial value |
-> Fun n a b | Reduction function |
Same as accum
but allow use ArityPeano
at each step Note
that in general case this will lead to O(n²) compilation time.
Arguments
:: (forall (k :: PeanoNum). t ('S k) -> (a, t k)) | Get value to apply to function |
-> t n | Initial value |
-> (ContVec n a, t 'Z) |
Apply all parameters to the function.
Arguments
:: Applicative f | |
=> (forall (k :: PeanoNum). t ('S k) -> (f a, t k)) | Get value to apply to function |
-> t n | Initial value |
-> (f (ContVec n a), t 'Z) |
Apply all parameters to the function using monadic actions. Note that for identity monad it's same as applyFun. Ignoring newtypes:
forall b. Fn n a b -> b ~ ContVec n a
Perform N reduction steps. This function doesn't involve N-ary function directly.
peanoToInt :: Proxy# n -> Int Source #
Conver peano number to int
dictionaryPred :: forall (k :: PeanoNum) r. n ~ 'S k => Proxy# n -> (ArityPeano k => r) -> r Source #
Provide ArityPeano
dictionary for previous Peano number. GHC
cannot infer that when ArityPeano n
and n ~ S k
we have
instance for k
as well. So we have to provide such dictionary
manually.
It's not possible to have non-⊥ implementation for Z
but
neither it's possible to call it.
Instances
ArityPeano 'Z Source # | |
Defined in Data.Vector.Fixed.Cont Methods accum :: (forall (k :: PeanoNum). t ('S k) -> a -> t k) -> (t 'Z -> b) -> t 'Z -> Fun 'Z a b Source # accumPeano :: (forall (k :: PeanoNum). ArityPeano k => t ('S k) -> a -> t k) -> (t 'Z -> b) -> t 'Z -> Fun 'Z a b Source # applyFun :: (forall (k :: PeanoNum). t ('S k) -> (a, t k)) -> t 'Z -> (ContVec 'Z a, t 'Z) Source # applyFunM :: Applicative f => (forall (k :: PeanoNum). t ('S k) -> (f a, t k)) -> t 'Z -> (f (ContVec 'Z a), t 'Z) Source # reducePeano :: (forall (k :: PeanoNum). t ('S k) -> t k) -> t 'Z -> t 'Z Source # peanoToInt :: Proxy# 'Z -> Int Source # dictionaryPred :: forall (k :: PeanoNum) r. 'Z ~ 'S k => Proxy# 'Z -> (ArityPeano k => r) -> r Source # | |
ArityPeano n => ArityPeano ('S n) Source # | |
Defined in Data.Vector.Fixed.Cont Methods accum :: (forall (k :: PeanoNum). t ('S k) -> a -> t k) -> (t 'Z -> b) -> t ('S n) -> Fun ('S n) a b Source # accumPeano :: (forall (k :: PeanoNum). ArityPeano k => t ('S k) -> a -> t k) -> (t 'Z -> b) -> t ('S n) -> Fun ('S n) a b Source # applyFun :: (forall (k :: PeanoNum). t ('S k) -> (a, t k)) -> t ('S n) -> (ContVec ('S n) a, t 'Z) Source # applyFunM :: Applicative f => (forall (k :: PeanoNum). t ('S k) -> (f a, t k)) -> t ('S n) -> (f (ContVec ('S n) a), t 'Z) Source # reducePeano :: (forall (k :: PeanoNum). t ('S k) -> t k) -> t ('S n) -> t 'Z Source # peanoToInt :: Proxy# ('S n) -> Int Source # dictionaryPred :: forall (k :: PeanoNum) r. 'S n ~ 'S k => Proxy# ('S n) -> (ArityPeano k => r) -> r Source # |
Arguments
:: forall (n :: PeanoNum) t a. ArityPeano n | |
=> (forall (k :: PeanoNum). t ('S k) -> (a, t k)) | Get value to apply to function |
-> t n | Initial value |
-> ContVec n a | N-ary function |
Apply all parameters to the function.
Arguments
:: forall f (n :: PeanoNum) t a. (Applicative f, ArityPeano n) | |
=> (forall (k :: PeanoNum). t ('S k) -> (f a, t k)) | Get value to apply to function |
-> t n | Initial value |
-> f (ContVec n a) |
Apply all parameters to the function using applicative actions.
class Index (k :: PeanoNum) (n :: PeanoNum) where Source #
Type class for indexing of vector of length n
with statically
known index k
Methods
getF :: Proxy# k -> Fun n a a Source #
putF :: Proxy# k -> a -> Fun n a r -> Fun n a r Source #
lensF :: Functor f => Proxy# k -> (a -> f a) -> Fun n a r -> Fun n a (f r) Source #
Combinators
constFun :: forall (n :: PeanoNum) a b. Fun n a b -> Fun ('S n) a b Source #
Prepend ignored parameter to function
curryFirst :: forall (n :: PeanoNum) a b. Fun ('S n) a b -> a -> Fun n a b Source #
Curry first parameter of n-ary function
uncurryFirst :: forall a (n :: PeanoNum) b. (a -> Fun n a b) -> Fun ('S n) a b Source #
Uncurry first parameter of n-ary function
curryLast :: forall (n :: PeanoNum) a b. ArityPeano n => Fun ('S n) a b -> Fun n a (a -> b) Source #
Curry last parameter of n-ary function
curryMany :: forall (n :: PeanoNum) (k :: PeanoNum) a b. ArityPeano n => Fun (Add n k) a b -> Fun n a (Fun k a b) Source #
Curry n first parameters of n-ary function
apLast :: forall (n :: PeanoNum) a b. ArityPeano n => Fun ('S n) a b -> a -> Fun n a b Source #
Apply last parameter to function. Unlike apFun
we need to
traverse all parameters but last hence Arity
constraint.
shuffleFun :: forall (n :: PeanoNum) b a r. ArityPeano n => (b -> Fun n a r) -> Fun n a (b -> r) Source #
Move function parameter to the result of N-ary function.
withFun :: forall (n :: PeanoNum) a b c. (Fun n a b -> Fun n a c) -> Fun ('S n) a b -> Fun ('S n) a c Source #
Recursive step for the function
dimapFun :: forall (n :: PeanoNum) a b c d. ArityPeano n => (a -> b) -> (c -> d) -> Fun n b c -> Fun n a d Source #
Apply function to parameters and result of Fun
simultaneously.
Vector type class
type family Dim (v :: Type -> Type) :: PeanoNum Source #
Size of vector expressed as Peano natural.
Instances
class ArityPeano (Dim v) => Vector (v :: Type -> Type) a where Source #
Type class for vectors with fixed length. Instance should provide
two functions: one to create vector from N
elements and another
for vector deconstruction. They must obey following law:
inspect v construct = v
For example instance for 2D vectors could be written as:
data V2 a = V2 a a type instance V2 = 2 instance Vector V2 a where construct = Fun V2 inspect (V2 a b) (Fun f) = f a b
Methods
construct :: Fun (Dim v) a (v a) Source #
N-ary function for creation of vectors. It takes N
elements
of array as parameters and return vector.
inspect :: v a -> Fun (Dim v) a b -> b Source #
Deconstruction of vector. It takes N-ary function as parameters and applies vector's elements to it.
basicIndex :: v a -> Int -> a Source #
Optional more efficient implementation of indexing. Shouldn't
be used directly, use !
instead.
Instances
Vector Complex a Source # | |
Vector Identity a Source # | |
Vector Only a Source # | |
Vector (Proxy :: Type -> Type) a Source # | |
Vector (Empty :: Type -> Type) a Source # | |
Arity n => Vector (VecList n) a Source # | |
ArityPeano n => Vector (VecPeano n) a Source # | |
Arity n => Vector (Vec n) a Source # | |
ArityPeano n => Vector (ContVec n) a Source # | |
(Arity n, Prim a) => Vector (Vec n) a Source # | |
(Arity n, Storable a) => Vector (Vec n) a Source # | |
Arity n => Vector (Vec n) a Source # | |
(n <= 64, Arity n, a ~ Bool) => Vector (BitVec n) a Source # | |
(Arity n, Unbox n a) => Vector (Vec n) a Source # | |
b ~ a => Vector ((,) b) a Source # | Note this instance (and other instances for tuples) is
essentially monomorphic in element type. Vector type v of 2
element tuple |
Vector v a => Vector (ViaFixed v) a Source # | |
(b ~ a, c ~ a) => Vector ((,,) b c) a Source # | |
(b ~ a, c ~ a, d ~ a) => Vector ((,,,) b c d) a Source # | |
(Arity n, Unbox n a, Unbox n b) => Vector (T2 n a b) (a, b) Source # | |
(b ~ a, c ~ a, d ~ a, e ~ a) => Vector ((,,,,) b c d e) a Source # | |
(Arity n, Unbox n a, Unbox n b, Unbox n c) => Vector (T3 n a b c) (a, b, c) Source # | |
(b ~ a, c ~ a, d ~ a, e ~ a, f ~ a) => Vector ((,,,,,) b c d e f) a Source # | |
(b ~ a, c ~ a, d ~ a, e ~ a, f ~ a, g ~ a) => Vector ((,,,,,,) b c d e f g) a Source # | |
length :: ArityPeano (Dim v) => v a -> Int Source #
Length of vector. Function doesn't evaluate its argument.
Vector as continuation
newtype ContVec (n :: PeanoNum) a Source #
Vector represented as continuation. Alternative wording: it's Church encoded N-element vector.
Instances
consPeano :: forall a (n :: PeanoNum). a -> ContVec n a -> ContVec ('S n) a Source #
Cons values to the ContVec
.
runContVec :: forall (n :: PeanoNum) a r. Fun n a r -> ContVec n a -> r Source #
Run continuation vector. It's same as inspect
but with
arguments flipped.
Construction of ContVec
cvec :: Vector v a => v a -> ContVec (Dim v) a Source #
Convert regular vector to continuation based one.
fromList :: forall (n :: PeanoNum) a. ArityPeano n => [a] -> ContVec n a Source #
Convert list to continuation-based vector. Will throw error if list is shorter than resulting vector.
fromList' :: forall (n :: PeanoNum) a. ArityPeano n => [a] -> ContVec n a Source #
Same as fromList
bu throws error is list doesn't have same
length as vector.
fromListM :: forall (n :: PeanoNum) a. ArityPeano n => [a] -> Maybe (ContVec n a) Source #
Convert list to continuation-based vector. Will fail with
Nothing
if list doesn't have right length.
toList :: forall (n :: PeanoNum) a. ArityPeano n => ContVec n a -> [a] Source #
Convert vector to the list
replicate :: forall (n :: PeanoNum) a. ArityPeano n => a -> ContVec n a Source #
Execute monadic action for every element of vector. Synonym for pure
.
replicateM :: forall (n :: PeanoNum) f a. (ArityPeano n, Applicative f) => f a -> f (ContVec n a) Source #
Execute monadic action for every element of vector.
generate :: forall (n :: PeanoNum) a. ArityPeano n => (Int -> a) -> ContVec n a Source #
Generate vector from function which maps element's index to its value.
generateM :: forall f (n :: PeanoNum) a. (Applicative f, ArityPeano n) => (Int -> f a) -> f (ContVec n a) Source #
Generate vector from monadic function which maps element's index to its value.
unfoldr :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> (a, b)) -> b -> ContVec n a Source #
Unfold vector.
basis :: forall a (n :: PeanoNum). (Num a, ArityPeano n) => Int -> ContVec n a Source #
Unit vector along Nth axis.
Constructors
cons :: forall a (n :: PeanoNum). a -> ContVec n a -> ContVec ('S n) a Source #
O(1) Prepend element to vector
consV :: forall (n :: PeanoNum) a. ArityPeano n => ContVec N1 a -> ContVec n a -> ContVec ('S n) a Source #
Prepend single element vector to another vector.
snoc :: forall (n :: PeanoNum) a. ArityPeano n => a -> ContVec n a -> ContVec ('S n) a Source #
O(1) Append element to vector
concat :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, ArityPeano k, ArityPeano (Add n k)) => ContVec n a -> ContVec k a -> ContVec (Add n k) a Source #
Concatenate vector
Transformations
map :: forall (n :: PeanoNum) a b. ArityPeano n => (a -> b) -> ContVec n a -> ContVec n b Source #
Map over vector. Synonym for fmap
imap :: forall (n :: PeanoNum) a b. ArityPeano n => (Int -> a -> b) -> ContVec n a -> ContVec n b Source #
Apply function to every element of the vector and its index.
mapM :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (a -> f b) -> ContVec n a -> f (ContVec n b) Source #
Effectful map over vector.
imapM :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (Int -> a -> f b) -> ContVec n a -> f (ContVec n b) Source #
Apply monadic function to every element of the vector and its index.
mapM_ :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (a -> f b) -> ContVec n a -> f () Source #
Apply monadic action to each element of vector and ignore result.
imapM_ :: forall (n :: PeanoNum) f a b. (ArityPeano n, Applicative f) => (Int -> a -> f b) -> ContVec n a -> f () Source #
Apply monadic action to each element of vector and its index and ignore result.
scanl :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> a -> b) -> b -> ContVec n a -> ContVec ('S n) b Source #
Left scan over vector
scanl1 :: forall (n :: PeanoNum) a. ArityPeano n => (a -> a -> a) -> ContVec n a -> ContVec n a Source #
Left scan over vector
sequence :: forall (n :: PeanoNum) f a. (ArityPeano n, Applicative f) => ContVec n (f a) -> f (ContVec n a) Source #
Evaluate every action in the vector from left to right.
sequence_ :: forall (n :: PeanoNum) f a. (ArityPeano n, Applicative f) => ContVec n (f a) -> f () Source #
Evaluate every action in the vector from left to right and ignore result.
distribute :: forall f (n :: PeanoNum) a. (Functor f, ArityPeano n) => f (ContVec n a) -> ContVec n (f a) Source #
The dual of sequenceA
collect :: forall f (n :: PeanoNum) a b. (Functor f, ArityPeano n) => (a -> ContVec n b) -> f a -> ContVec n (f b) Source #
reverse :: forall (n :: PeanoNum) a. ArityPeano n => ContVec n a -> ContVec n a Source #
Reverse order of elements in the vector
Zips
zipWith :: forall (n :: PeanoNum) a b c. ArityPeano n => (a -> b -> c) -> ContVec n a -> ContVec n b -> ContVec n c Source #
Zip two vector together using function.
zipWith3 :: forall (n :: PeanoNum) a b c d. ArityPeano n => (a -> b -> c -> d) -> ContVec n a -> ContVec n b -> ContVec n c -> ContVec n d Source #
Zip three vectors together
izipWith :: forall (n :: PeanoNum) a b c. ArityPeano n => (Int -> a -> b -> c) -> ContVec n a -> ContVec n b -> ContVec n c Source #
Zip two vector together using function which takes element index as well.
izipWith3 :: forall (n :: PeanoNum) a b c d. ArityPeano n => (Int -> a -> b -> c -> d) -> ContVec n a -> ContVec n b -> ContVec n c -> ContVec n d Source #
Zip three vectors together
zipWithM :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (a -> b -> f c) -> ContVec n a -> ContVec n b -> f (ContVec n c) Source #
Zip two vector together using monadic function.
zipWithM_ :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (a -> b -> f c) -> ContVec n a -> ContVec n b -> f () Source #
izipWithM :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (Int -> a -> b -> f c) -> ContVec n a -> ContVec n b -> f (ContVec n c) Source #
Zip two vector together using monadic function which takes element index as well..
izipWithM_ :: forall (n :: PeanoNum) f a b c. (ArityPeano n, Applicative f) => (Int -> a -> b -> f c) -> ContVec n a -> ContVec n b -> f () Source #
Getters
head :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, n ~ 'S k) => ContVec n a -> a Source #
Finalizer function for getting head of the vector.
index :: forall (n :: PeanoNum) a. ArityPeano n => Int -> ContVec n a -> a Source #
O(n) Get value at specified index.
element :: forall (n :: PeanoNum) f a. (ArityPeano n, Functor f) => Int -> (a -> f a) -> ContVec n a -> f (ContVec n a) Source #
Twan van Laarhoven lens for continuation based vector
Vector construction
Folds
foldl :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> a -> b) -> b -> ContVec n a -> b Source #
Left fold over continuation vector.
foldl' :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> a -> b) -> b -> ContVec n a -> b Source #
Strict left fold over continuation vector.
foldl1 :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, n ~ 'S k) => (a -> a -> a) -> ContVec n a -> a Source #
Left fold without base case. It's total because it requires vector to be nonempty
foldl1' :: forall (n :: PeanoNum) (k :: PeanoNum) a. (ArityPeano n, n ~ 'S k) => (a -> a -> a) -> ContVec n a -> a Source #
Left fold without base case. It's total because it requires vector to be nonempty
foldr :: forall (n :: PeanoNum) a b. ArityPeano n => (a -> b -> b) -> b -> ContVec n a -> b Source #
Right fold over continuation vector
ifoldl :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> Int -> a -> b) -> b -> ContVec n a -> b Source #
Left fold over continuation vector.
ifoldl' :: forall (n :: PeanoNum) b a. ArityPeano n => (b -> Int -> a -> b) -> b -> ContVec n a -> b Source #
Strict left fold over continuation vector.
ifoldr :: forall (n :: PeanoNum) a b. ArityPeano n => (Int -> a -> b -> b) -> b -> ContVec n a -> b Source #
Right fold over continuation vector
foldM :: forall (n :: PeanoNum) m b a. (ArityPeano n, Monad m) => (b -> a -> m b) -> b -> ContVec n a -> m b Source #
Monadic left fold over continuation vector.
ifoldM :: forall (n :: PeanoNum) m b a. (ArityPeano n, Monad m) => (b -> Int -> a -> m b) -> b -> ContVec n a -> m b Source #
Monadic left fold over continuation vector.
Special folds
sum :: forall a (n :: PeanoNum). (Num a, ArityPeano n) => ContVec n a -> a Source #
Sum all elements in the vector.
minimum :: forall a (n :: PeanoNum) (k :: PeanoNum). (Ord a, ArityPeano n, n ~ 'S k) => ContVec n a -> a Source #
Minimal element of vector.
maximum :: forall a (n :: PeanoNum) (k :: PeanoNum). (Ord a, ArityPeano n, n ~ 'S k) => ContVec n a -> a Source #
Maximal element of vector.
and :: forall (n :: PeanoNum). ArityPeano n => ContVec n Bool -> Bool Source #
Conjunction of elements of a vector.
or :: forall (n :: PeanoNum). ArityPeano n => ContVec n Bool -> Bool Source #
Disjunction of all elements of a vector.
all :: forall (n :: PeanoNum) a. ArityPeano n => (a -> Bool) -> ContVec n a -> Bool Source #
Determines whether all elements of vector satisfy predicate.
any :: forall (n :: PeanoNum) a. ArityPeano n => (a -> Bool) -> ContVec n a -> Bool Source #
Determines whether any of element of vector satisfy predicate.