fixed-vector-0.2.0.0: Generic vectors with fixed length

Safe HaskellNone

Data.Vector.Fixed.Cont

Contents

Description

Continuations-based API

Synopsis

Vector as continuation

data ContVecT m n a Source

Vector represented as continuation.

Instances

Arity n => Functor (ContVecT m n) 
Arity n => Applicative (ContVecT m n) 

type ContVec = ContVecT IdSource

Vector as continuation without monadic context.

Synonyms for small numerals

type N1 = S ZSource

type N2 = S N1Source

type N3 = S N2Source

type N4 = S N3Source

type N5 = S N4Source

type N6 = S N5Source

Construction of ContVec

cvec :: (Vector v a, Dim v ~ n, Monad m) => v a -> ContVecT m n aSource

Convert regular vector to continuation

fromList :: forall m n a. Arity n => [a] -> ContVecT m n aSource

Convert list to continuation-based vector. Will throw error if list is shorter than resulting vector.

replicate :: forall m n a. Arity n => a -> ContVecT m n aSource

Execute monadic action for every element of vector. Synonym for pure.

replicateM :: forall m n a. (Arity n, Monad m) => m a -> ContVecT m n aSource

Execute monadic action for every element of vector.

generate :: forall m n a. Arity n => (Int -> a) -> ContVecT m n aSource

Generate vector from function which maps element's index to its value.

generateM :: forall m n a. (Monad m, Arity n) => (Int -> m a) -> ContVecT m n aSource

Generate vector from monadic function which maps element's index to its value.

basis :: forall m n a. (Num a, Arity n) => Int -> ContVecT m n aSource

Unit vector along Nth axis.

Constructors

mk1 :: a -> ContVecT m N1 aSource

mk2 :: a -> a -> ContVecT m N2 aSource

mk3 :: a -> a -> a -> ContVecT m N3 aSource

mk4 :: a -> a -> a -> a -> ContVecT m N4 aSource

mk5 :: a -> a -> a -> a -> a -> ContVecT m N5 aSource

Transformations

map :: Arity n => (a -> b) -> ContVecT m n a -> ContVecT m n bSource

Map over vector. Synonym for fmap

imap :: Arity n => (Int -> a -> b) -> ContVecT m n a -> ContVecT m n bSource

Apply function to every element of the vector and its index.

mapM :: (Arity n, Monad m) => (a -> m b) -> ContVecT m n a -> ContVecT m n bSource

Monadic map over vector.

imapM :: (Arity n, Monad m) => (Int -> a -> m b) -> ContVecT m n a -> ContVecT m n bSource

Apply monadic function to every element of the vector and its index.

tail :: ContVecT m (S n) a -> ContVecT m n aSource

O(1) Tail of vector.

cons :: a -> ContVecT m n a -> ContVecT m (S n) aSource

O(1) Prepend element to vector

Zips

zipWith :: Arity n => (a -> b -> c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n cSource

Zip two vector together using function.

izipWith :: Arity n => (Int -> a -> b -> c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n cSource

Zip two vector together using function which takes element index as well.

zipWithM :: (Arity n, Monad m) => (a -> b -> m c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n cSource

Zip two vector together using monadic function.

izipWithM :: (Arity n, Monad m) => (Int -> a -> b -> m c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n cSource

Zip two vector together using monadic function which takes element index as well..

Running ContVec

Only way to get result from continuation vector is to apply finalizer function to them using runContVecT, runContVecM or runContVec. Getters and folds are defined as such finalizer functions.

runContVecTSource

Arguments

:: (Monad m, Arity n) 
=> Fun n a r

finalizer function

-> ContVecT m n a

vector

-> m r 

Run continuation vector using non-monadic finalizer.

runContVecMSource

Arguments

:: Arity n 
=> Fun n a (m r)

finalizer function

-> ContVecT m n a

vector

-> m r 

Run continuation vector using monadic finalizer.

runContVec :: Arity n => Fun n a r -> ContVec n a -> rSource

Run continuation vector.

Getters

head :: forall n a. Arity (S n) => Fun (S n) a aSource

Finalizer function for getting head of the vector.

Vector construction

vector :: (Vector v a, Dim v ~ n) => ContVec n a -> v aSource

Convert continuation to the vector.

vectorM :: (Vector v a, Dim v ~ n, Monad m) => ContVecT m n a -> m (v a)Source

Convert continuation to the vector.

Folds

foldl :: forall n a b. Arity n => (b -> a -> b) -> b -> Fun n a bSource

Left fold over continuation vector.

foldl1 :: forall n a. Arity (S n) => (a -> a -> a) -> Fun (S n) a aSource

Left fold.

foldr :: forall n a b. Arity n => (a -> b -> b) -> b -> Fun n a bSource

Right fold over continuation vector

ifoldl :: forall n a b. Arity n => (b -> Int -> a -> b) -> b -> Fun n a bSource

Left fold over continuation vector.

ifoldr :: forall n a b. Arity n => (Int -> a -> b -> b) -> b -> Fun n a bSource

Right fold over continuation vector

foldM :: forall n m a b. (Arity n, Monad m) => (b -> a -> m b) -> b -> Fun n a (m b)Source

Monadic left fold over continuation vector.

ifoldM :: forall n m a b. (Arity n, Monad m) => (b -> Int -> a -> m b) -> b -> Fun n a (m b)Source

Monadic left fold over continuation vector.

Special folds

sum :: (Num a, Arity n) => Fun n a aSource

Sum all elements in the vector.

minimum :: (Ord a, Arity (S n)) => Fun (S n) a aSource

Minimal element of vector.

maximum :: (Ord a, Arity (S n)) => Fun (S n) a aSource

Maximal element of vector.

and :: Arity n => Fun n Bool BoolSource

Conjunction of elements of a vector.

or :: Arity n => Fun n Bool BoolSource

Disjunction of all elements of a vector.

all :: Arity n => (a -> Bool) -> Fun n a BoolSource

Determines whether all elements of vector satisfy predicate.

any :: Arity n => (a -> Bool) -> Fun n a BoolSource

Determines whether any of element of vector satisfy predicate.

Data types

data VecList n a Source

Vector based on the lists. Not very useful by itself but is necessary for implementation.

Instances

Arity n => VectorN VecList n a 
Arity n => Vector (VecList n) a 
Eq a => Eq (VecList n a) 
Show a => Show (VecList n a)