fixed-vector-0.9.0.0: Generic vectors with statically known size.

Safe HaskellNone
LanguageHaskell98

Data.Vector.Fixed

Contents

Description

Generic API for vectors with fixed length.

For encoding of vector size library uses Peano naturals defined in the library. At come point in the future it would make sense to switch to new GHC type level numerals.

Common pitfalls

Library provide instances for tuples. But there's a catch. Tuples are monomorphic in element type. Let consider 2-tuple (Int,Int). Vector type v is (,) Int and only allowed element type is Int. Because of that we cannot change element type and following code will fail:

>>> map (== 1) ((1,2) :: (Int,Int))

<interactive>:3:1:
    Couldn't match type `Int' with `Bool'
    In the expression: F.map (== 1) ((1, 2) :: (Int, Int))
    In an equation for `it': it = map (== 1) ((1, 2) :: (Int, Int))

To make it work we need to change vector type as well. Functions from module Data.Vector.Fixed.Generic provide this functionality.

>>> map (== 1) ((1,2) :: (Int,Int)) :: (Bool,Bool)
(True,False)

Synopsis

Vector type class

Vector size

type family Dim (v :: * -> *) Source #

Size of vector expressed as type-level natural.

Instances

type Dim Complex Source # 
type Dim Complex = N2
type Dim Empty Source # 
type Dim Empty = Z
type Dim Only Source # 
type Dim Only = S Z
type Dim ((,) a) Source # 
type Dim ((,) a) = N2
type Dim (Proxy *) Source # 
type Dim (Proxy *) = Z
type Dim (ContVec n) Source # 
type Dim (ContVec n) = n
type Dim (VecList n) Source # 
type Dim (VecList n) = n
type Dim (Vec n) Source # 
type Dim (Vec n) = n
type Dim (Vec n) Source # 
type Dim (Vec n) = n
type Dim (Vec n) Source # 
type Dim (Vec n) = n
type Dim (Vec n) Source # 
type Dim (Vec n) = n
type Dim ((,,) a b) Source # 
type Dim ((,,) a b) = N3
type Dim ((,,,) a b c) Source # 
type Dim ((,,,) a b c) = N4
type Dim ((,,,,) a b c d) Source # 
type Dim ((,,,,) a b c d) = N5
type Dim ((,,,,,) a b c d e) Source # 
type Dim ((,,,,,) a b c d e) = N6
type Dim ((,,,,,,) a b c d e f) Source # 
type Dim ((,,,,,,) a b c d e f) = S N6

data Z Source #

Type level zero

Instances

Arity Z Source # 

Methods

accum :: (forall k. t (S k) -> a -> t k) -> (t Z -> b) -> t Z -> Fun Z a b Source #

applyFun :: (forall k. t (S k) -> (a, t k)) -> t Z -> Fn Z a b -> (b, t Z) Source #

applyFunM :: Monad m => (forall k. t (S k) -> m (a, t k)) -> t Z -> m (ContVec Z a, t Z) Source #

arity :: Z -> Int Source #

reverseF :: Fun Z a b -> Fun Z a b Source #

uncurryMany :: Fun (Add Z k) a b -> Fun Z a (Fun k a b) Source #

gunfoldF :: Data a => (forall b x. Data b => c (b -> x) -> c x) -> T_gunfold c r a Z -> c r Source #

NatIso Z 0 Source # 
Arity n => Index Z (S n) Source # 

Methods

getF :: Z -> Fun (S n) a a Source #

putF :: Z -> a -> Fun (S n) a r -> Fun (S n) a r Source #

lensF :: Functor f => Z -> (a -> f a) -> Fun (S n) a r -> Fun (S n) a (f r) Source #

type Add Z n Source # 
type Add Z n = n
type Fn Z a b Source # 
type Fn Z a b = b

data S n Source #

Successor of n

Instances

Arity n => Index Z (S n) Source # 

Methods

getF :: Z -> Fun (S n) a a Source #

putF :: Z -> a -> Fun (S n) a r -> Fun (S n) a r Source #

lensF :: Functor f => Z -> (a -> f a) -> Fun (S n) a r -> Fun (S n) a (f r) Source #

Arity n => Arity (S n) Source # 

Methods

accum :: (forall k. t (S k) -> a -> t k) -> (t Z -> b) -> t (S n) -> Fun (S n) a b Source #

applyFun :: (forall k. t (S k) -> (a, t k)) -> t (S n) -> Fn (S n) a b -> (b, t Z) Source #

applyFunM :: Monad m => (forall k. t (S k) -> m (a, t k)) -> t (S n) -> m (ContVec (S n) a, t Z) Source #

arity :: S n -> Int Source #

reverseF :: Fun (S n) a b -> Fun (S n) a b Source #

uncurryMany :: Fun (Add (S n) k) a b -> Fun (S n) a (Fun k a b) Source #

gunfoldF :: Data a => (forall b x. Data b => c (b -> x) -> c x) -> T_gunfold c r a (S n) -> c r Source #

(NatIso k ((-) n 1), (~) * (ToPeano ((-) n 1)) k, (~) * (ToPeano n) (S k), (~) Nat n ((+) 1 ((-) n 1))) => NatIso (S k) n Source # 
Index k n => Index (S k) (S n) Source # 

Methods

getF :: S k -> Fun (S n) a a Source #

putF :: S k -> a -> Fun (S n) a r -> Fun (S n) a r Source #

lensF :: Functor f => S k -> (a -> f a) -> Fun (S n) a r -> Fun (S n) a (f r) Source #

type Add (S n) k Source # 
type Add (S n) k = S (Add n k)
type Fn (S n) a b Source # 
type Fn (S n) a b = a -> Fn n a b

Synonyms for small numerals

type N1 = S Z Source #

type N2 = S N1 Source #

type N3 = S N2 Source #

type N4 = S N3 Source #

type N5 = S N4 Source #

type N6 = S N5 Source #

Type class

class Arity (Dim v) => Vector v a where Source #

Type class for vectors with fixed length. Instance should provide two functions: one to create vector and another for vector deconstruction. They must obey following law:

inspect v construct = v

Minimal complete definition

construct, inspect

Methods

construct :: Fun (Dim v) a (v a) Source #

N-ary function for creation of vectors.

inspect :: v a -> Fun (Dim v) a b -> b Source #

Deconstruction of vector.

basicIndex :: v a -> Int -> a Source #

Optional more efficient implementation of indexing. Shouldn't be used directly, use ! instead.

Instances

RealFloat a => Vector Complex a Source # 

Methods

construct :: Fun (Dim Complex) a (Complex a) Source #

inspect :: Complex a -> Fun (Dim Complex) a b -> b Source #

basicIndex :: Complex a -> Int -> a Source #

Vector Empty a Source # 

Methods

construct :: Fun (Dim Empty) a (Empty a) Source #

inspect :: Empty a -> Fun (Dim Empty) a b -> b Source #

basicIndex :: Empty a -> Int -> a Source #

Vector Only a Source # 

Methods

construct :: Fun (Dim Only) a (Only a) Source #

inspect :: Only a -> Fun (Dim Only) a b -> b Source #

basicIndex :: Only a -> Int -> 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 (Int,Int) is (,) Int so it will only work with elements of type Int.

Methods

construct :: Fun (Dim ((,) b)) a (b, a) Source #

inspect :: (b, a) -> Fun (Dim ((,) b)) a b -> b Source #

basicIndex :: (b, a) -> Int -> a Source #

Vector (Proxy *) a Source # 

Methods

construct :: Fun (Dim (Proxy *)) a (Proxy * a) Source #

inspect :: Proxy * a -> Fun (Dim (Proxy *)) a b -> b Source #

basicIndex :: Proxy * a -> Int -> a Source #

Arity n => Vector (ContVec n) a Source # 

Methods

construct :: Fun (Dim (ContVec n)) a (ContVec n a) Source #

inspect :: ContVec n a -> Fun (Dim (ContVec n)) a b -> b Source #

basicIndex :: ContVec n a -> Int -> a Source #

Arity n => Vector (VecList n) a Source # 

Methods

construct :: Fun (Dim (VecList n)) a (VecList n a) Source #

inspect :: VecList n a -> Fun (Dim (VecList n)) a b -> b Source #

basicIndex :: VecList n a -> Int -> a Source #

Arity n => Vector (Vec n) a Source # 

Methods

construct :: Fun (Dim (Vec n)) a (Vec n a) Source #

inspect :: Vec n a -> Fun (Dim (Vec n)) a b -> b Source #

basicIndex :: Vec n a -> Int -> a Source #

(Arity n, Prim a) => Vector (Vec n) a Source # 

Methods

construct :: Fun (Dim (Vec n)) a (Vec n a) Source #

inspect :: Vec n a -> Fun (Dim (Vec n)) a b -> b Source #

basicIndex :: Vec n a -> Int -> a Source #

(Arity n, Storable a) => Vector (Vec n) a Source # 

Methods

construct :: Fun (Dim (Vec n)) a (Vec n a) Source #

inspect :: Vec n a -> Fun (Dim (Vec n)) a b -> b Source #

basicIndex :: Vec n a -> Int -> a Source #

Unbox n a => Vector (Vec n) a Source # 

Methods

construct :: Fun (Dim (Vec n)) a (Vec n a) Source #

inspect :: Vec n a -> Fun (Dim (Vec n)) a b -> b Source #

basicIndex :: Vec n a -> Int -> a Source #

((~) * b a, (~) * c a) => Vector ((,,) b c) a Source # 

Methods

construct :: Fun (Dim ((,,) b c)) a (b, c, a) Source #

inspect :: (b, c, a) -> Fun (Dim ((,,) b c)) a b -> b Source #

basicIndex :: (b, c, a) -> Int -> a Source #

((~) * b a, (~) * c a, (~) * d a) => Vector ((,,,) b c d) a Source # 

Methods

construct :: Fun (Dim ((,,,) b c d)) a (b, c, d, a) Source #

inspect :: (b, c, d, a) -> Fun (Dim ((,,,) b c d)) a b -> b Source #

basicIndex :: (b, c, d, a) -> Int -> a Source #

((~) * b a, (~) * c a, (~) * d a, (~) * e a) => Vector ((,,,,) b c d e) a Source # 

Methods

construct :: Fun (Dim ((,,,,) b c d e)) a (b, c, d, e, a) Source #

inspect :: (b, c, d, e, a) -> Fun (Dim ((,,,,) b c d e)) a b -> b Source #

basicIndex :: (b, c, d, e, a) -> Int -> a Source #

((~) * b a, (~) * c a, (~) * d a, (~) * e a, (~) * f a) => Vector ((,,,,,) b c d e f) a Source # 

Methods

construct :: Fun (Dim ((,,,,,) b c d e f)) a (b, c, d, e, f, a) Source #

inspect :: (b, c, d, e, f, a) -> Fun (Dim ((,,,,,) b c d e f)) a b -> b Source #

basicIndex :: (b, c, d, e, f, a) -> Int -> a Source #

((~) * b a, (~) * c a, (~) * d a, (~) * e a, (~) * f a, (~) * g a) => Vector ((,,,,,,) b c d e f g) a Source # 

Methods

construct :: Fun (Dim ((,,,,,,) b c d e f g)) a (b, c, d, e, f, g, a) Source #

inspect :: (b, c, d, e, f, g, a) -> Fun (Dim ((,,,,,,) b c d e f g)) a b -> b Source #

basicIndex :: (b, c, d, e, f, g, a) -> Int -> a Source #

class (Vector (v n) a, Dim (v n) ~ n) => VectorN v n a Source #

Vector parametrized by length. In ideal world it should be:

forall n. (Arity n, Vector (v n) a, Dim (v n) ~ n) => VectorN v a

Alas polymorphic constraints aren't allowed in haskell.

Instances

Arity n => VectorN ContVec n a Source # 
Arity n => VectorN VecList n a Source # 
Arity n => VectorN Vec n a Source # 
(Arity n, Prim a) => VectorN Vec n a Source # 
(Arity n, Storable a) => VectorN Vec n a Source # 
Unbox n a => VectorN Vec n a Source # 

class Arity n Source #

Type class for handling n-ary functions.

Minimal complete definition

accum, applyFun, applyFunM, arity, reverseF, uncurryMany, gunfoldF

Instances

Arity Z Source # 

Methods

accum :: (forall k. t (S k) -> a -> t k) -> (t Z -> b) -> t Z -> Fun Z a b Source #

applyFun :: (forall k. t (S k) -> (a, t k)) -> t Z -> Fn Z a b -> (b, t Z) Source #

applyFunM :: Monad m => (forall k. t (S k) -> m (a, t k)) -> t Z -> m (ContVec Z a, t Z) Source #

arity :: Z -> Int Source #

reverseF :: Fun Z a b -> Fun Z a b Source #

uncurryMany :: Fun (Add Z k) a b -> Fun Z a (Fun k a b) Source #

gunfoldF :: Data a => (forall b x. Data b => c (b -> x) -> c x) -> T_gunfold c r a Z -> c r Source #

Arity n => Arity (S n) Source # 

Methods

accum :: (forall k. t (S k) -> a -> t k) -> (t Z -> b) -> t (S n) -> Fun (S n) a b Source #

applyFun :: (forall k. t (S k) -> (a, t k)) -> t (S n) -> Fn (S n) a b -> (b, t Z) Source #

applyFunM :: Monad m => (forall k. t (S k) -> m (a, t k)) -> t (S n) -> m (ContVec (S n) a, t Z) Source #

arity :: S n -> Int Source #

reverseF :: Fun (S n) a b -> Fun (S n) a b Source #

uncurryMany :: Fun (Add (S n) k) a b -> Fun (S n) a (Fun k a b) Source #

gunfoldF :: Data a => (forall b x. Data b => c (b -> x) -> c x) -> T_gunfold c r a (S n) -> c r Source #

newtype Fun n a b Source #

Newtype wrapper which is used to make Fn injective. It's also a reader monad.

Constructors

Fun 

Fields

Instances

Arity n => Monad (Fun n a) Source # 

Methods

(>>=) :: Fun n a a -> (a -> Fun n a b) -> Fun n a b #

(>>) :: Fun n a a -> Fun n a b -> Fun n a b #

return :: a -> Fun n a a #

fail :: String -> Fun n a a #

Arity n => Functor (Fun n a) Source # 

Methods

fmap :: (a -> b) -> Fun n a a -> Fun n a b #

(<$) :: a -> Fun n a b -> Fun n a a #

Arity n => Applicative (Fun n a) Source # 

Methods

pure :: a -> Fun n a a #

(<*>) :: Fun n a (a -> b) -> Fun n a a -> Fun n a b #

(*>) :: Fun n a a -> Fun n a b -> Fun n a b #

(<*) :: Fun n a a -> Fun n a b -> Fun n a a #

length :: forall v a. Arity (Dim v) => v a -> Int Source #

Length of vector. Function doesn't evaluate its argument.

Constructors

There are several ways to construct fixed vectors except using their constructor if it's available. For small ones it's possible to use functions mk1, mk2, etc.

>>> mk3 'a' 'b' 'c' :: (Char,Char,Char)
('a','b','c')

Another option is to create tuple and convert it to desired vector type. For example:

v = convert (x,y,z)

It will work on if type of v is know from elsewhere. Same trick could be used to pattern match on the vector with opaque representation using view patterns

function :: Vec N3 Double -> ...
function (convert -> (x,y,z)) = ...

Third way is to use variadic function mkN. It works similarly to printf except it produces result of type ContVec which should be converted to vector of desired type by vector:

>>> vector $ mkN 'a' 'b' 'c' :: (Char,Char,Char)
('a','b','c')

Probably most generic way is to cons values to the ContVec and convert it vector of desired type using vector:

>>> vector $ 'a' <| 'b' <| 'c' <| empty :: (Char,Char,Char)
('a','b','c')

Constructors for vectors with small dimensions.

mk0 :: (Vector v a, Dim v ~ Z) => v a Source #

mk1 :: (Vector v a, Dim v ~ N1) => a -> v a Source #

mk2 :: (Vector v a, Dim v ~ N2) => a -> a -> v a Source #

mk3 :: (Vector v a, Dim v ~ N3) => a -> a -> a -> v a Source #

mk4 :: (Vector v a, Dim v ~ N4) => a -> a -> a -> a -> v a Source #

mk5 :: (Vector v a, Dim v ~ N5) => a -> a -> a -> a -> a -> v a Source #

Consing

data ContVec n a Source #

Vector represented as continuation. Alternative wording: it's Church encoded N-element vector.

Instances

Arity n => VectorN ContVec n a Source # 
Arity n => Make n a (ContVec n a) Source # 

Methods

make :: (ContVec Z a -> ContVec n a) -> ContVec n a

Arity n => Functor (ContVec n) Source # 

Methods

fmap :: (a -> b) -> ContVec n a -> ContVec n b #

(<$) :: a -> ContVec n b -> ContVec n a #

Arity n => Applicative (ContVec n) Source # 

Methods

pure :: a -> ContVec n a #

(<*>) :: ContVec n (a -> b) -> ContVec n a -> ContVec n b #

(*>) :: ContVec n a -> ContVec n b -> ContVec n b #

(<*) :: ContVec n a -> ContVec n b -> ContVec n a #

Arity n => Foldable (ContVec n) Source # 

Methods

fold :: Monoid m => ContVec n m -> m #

foldMap :: Monoid m => (a -> m) -> ContVec n a -> m #

foldr :: (a -> b -> b) -> b -> ContVec n a -> b #

foldr' :: (a -> b -> b) -> b -> ContVec n a -> b #

foldl :: (b -> a -> b) -> b -> ContVec n a -> b #

foldl' :: (b -> a -> b) -> b -> ContVec n a -> b #

foldr1 :: (a -> a -> a) -> ContVec n a -> a #

foldl1 :: (a -> a -> a) -> ContVec n a -> a #

toList :: ContVec n a -> [a] #

null :: ContVec n a -> Bool #

length :: ContVec n a -> Int #

elem :: Eq a => a -> ContVec n a -> Bool #

maximum :: Ord a => ContVec n a -> a #

minimum :: Ord a => ContVec n a -> a #

sum :: Num a => ContVec n a -> a #

product :: Num a => ContVec n a -> a #

Arity n => Traversable (ContVec n) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> ContVec n a -> f (ContVec n b) #

sequenceA :: Applicative f => ContVec n (f a) -> f (ContVec n a) #

mapM :: Monad m => (a -> m b) -> ContVec n a -> m (ContVec n b) #

sequence :: Monad m => ContVec n (m a) -> m (ContVec n a) #

Arity n => Vector (ContVec n) a Source # 

Methods

construct :: Fun (Dim (ContVec n)) a (ContVec n a) Source #

inspect :: ContVec n a -> Fun (Dim (ContVec n)) a b -> b Source #

basicIndex :: ContVec n a -> Int -> a Source #

type Dim (ContVec n) Source # 
type Dim (ContVec n) = n

empty :: ContVec Z a Source #

Create empty vector.

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

Convert continuation to the vector.

(<|) :: a -> ContVec n a -> ContVec (S n) a infixr 1 Source #

Cons value to continuation based vector.

Variadic function

class Make n a r Source #

Type class for variadic vector constructors.

Minimal complete definition

make

Instances

Arity n => Make n a (ContVec n a) Source # 

Methods

make :: (ContVec Z a -> ContVec n a) -> ContVec n a

((~) * a' a, Make (S n) a r) => Make n a' (a -> r) Source # 

Methods

make :: (ContVec Z a' -> ContVec n a') -> a -> r

mkN :: Make (S Z) a r => a -> r Source #

Variadic vector constructor. Resulting vector should be converted from ContVec using vector function. For example:

>>> vector $ mkN 'a' 'b' 'c' :: (Char,Char,Char)
('a','b','c')

Functions

replicate :: Vector v a => a -> v a Source #

Replicate value n times.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec2)
>>> replicate 1 :: Vec2 Int
fromList [1,1]
>>> replicate 2 :: (Double,Double,Double)
(2.0,2.0,2.0)
>>> import Data.Vector.Fixed.Boxed (Vec4)
>>> replicate "foo" :: Vec4 String
fromList ["foo","foo","foo","foo"]

replicateM :: (Vector v a, Monad m) => m a -> m (v a) Source #

Execute monadic action for every element of vector.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec2,Vec3)
>>> replicateM (Just 3) :: Maybe (Vec3 Int)
Just fromList [3,3,3]
>>> replicateM (putStrLn "Hi!") :: IO (Vec2 ())
Hi!
Hi!
fromList [(),()]

generate :: Vector v a => (Int -> a) -> v a Source #

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

Examples:

>>> import Data.Vector.Fixed.Unboxed (Vec4)
>>> generate (^2) :: Vec4 Int
fromList [0,1,4,9]

generateM :: (Monad m, Vector v a) => (Int -> m a) -> m (v a) Source #

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

unfoldr :: Vector v a => (b -> (a, b)) -> b -> v a Source #

Unfold vector.

basis :: (Vector v a, Num a) => Int -> v a Source #

Unit vector along Nth axis. If index is larger than vector dimensions returns zero vector.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec3)
>>> basis 0 :: Vec3 Int
fromList [1,0,0]
>>> basis 1 :: Vec3 Int
fromList [0,1,0]
>>> basis 3 :: Vec3 Int
fromList [0,0,0]

Modifying vectors

Transformations

head :: (Vector v a, Dim v ~ S n) => v a -> a Source #

First element of vector.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec3)
>>> let x = mk3 1 2 3 :: Vec3 Int
>>> head x
1

tail :: (Vector v a, Vector w a, Dim v ~ S (Dim w)) => v a -> w a Source #

Tail of vector.

Examples:

>>> import Data.Complex
>>> tail (1,2,3) :: Complex Double
2.0 :+ 3.0

cons :: (Vector v a, Vector w a, S (Dim v) ~ Dim w) => a -> v a -> w a Source #

Cons element to the vector

snoc :: (Vector v a, Vector w a, S (Dim v) ~ Dim w) => a -> v a -> w a Source #

Append element to the vector

concat :: (Vector v a, Vector u a, Vector w a, Add (Dim v) (Dim u) ~ Dim w) => v a -> u a -> w a Source #

reverse :: Vector v a => v a -> v a Source #

Reverse order of elements in the vector

Indexing & lenses

class Index k n Source #

Type class for indexing of vector when index value is known at compile time.

Minimal complete definition

getF, putF, lensF

Instances

Arity n => Index Z (S n) Source # 

Methods

getF :: Z -> Fun (S n) a a Source #

putF :: Z -> a -> Fun (S n) a r -> Fun (S n) a r Source #

lensF :: Functor f => Z -> (a -> f a) -> Fun (S n) a r -> Fun (S n) a (f r) Source #

Index k n => Index (S k) (S n) Source # 

Methods

getF :: S k -> Fun (S n) a a Source #

putF :: S k -> a -> Fun (S n) a r -> Fun (S n) a r Source #

lensF :: Functor f => S k -> (a -> f a) -> Fun (S n) a r -> Fun (S n) a (f r) Source #

(!) :: Vector v a => v a -> Int -> a Source #

Retrieve vector's element at index. Generic implementation is O(n) but more efficient one is used when possible.

index :: (Vector v a, Index k (Dim v)) => v a -> k -> a Source #

Get element from vector at statically known index

set :: (Vector v a, Index k (Dim v)) => k -> a -> v a -> v a Source #

Set n'th element in the vector

element :: (Vector v a, Functor f) => Int -> (a -> f a) -> v a -> f (v a) Source #

Twan van Laarhoven's lens for element of vector

elementTy :: (Vector v a, Index k (Dim v), Functor f) => k -> (a -> f a) -> v a -> f (v a) Source #

Twan van Laarhoven's lens for element of vector with statically known index.

Comparison

eq :: (Vector v a, Eq a) => v a -> v a -> Bool Source #

Test two vectors for equality.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec2)
>>> let v0 = basis 0 :: Vec2 Int
>>> let v1 = basis 1 :: Vec2 Int
>>> v0 `eq` v0
True
>>> v0 `eq` v1
False

ord :: (Vector v a, Ord a) => v a -> v a -> Ordering Source #

Lexicographic ordering of two vectors.

Maps

map :: (Vector v a, Vector v b) => (a -> b) -> v a -> v b Source #

Map over vector

mapM :: (Vector v a, Vector v b, Monad m) => (a -> m b) -> v a -> m (v b) Source #

Monadic map over vector.

mapM_ :: (Vector v a, Monad m) => (a -> m b) -> v a -> m () Source #

Apply monadic action to each element of vector and ignore result.

imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> v a -> v b Source #

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

imapM :: (Vector v a, Vector v b, Monad m) => (Int -> a -> m b) -> v a -> m (v b) Source #

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

imapM_ :: (Vector v a, Monad m) => (Int -> a -> m b) -> v a -> m () Source #

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

scanl :: (Vector v a, Vector w b, Dim w ~ S (Dim v)) => (b -> a -> b) -> b -> v a -> w b Source #

Left scan over vector

scanl1 :: Vector v a => (a -> a -> a) -> v a -> v a Source #

Left scan over vector

sequence :: (Vector v a, Vector v (m a), Monad m) => v (m a) -> m (v a) Source #

Evaluate every action in the vector from left to right.

sequence_ :: (Vector v (m a), Monad m) => v (m a) -> m () Source #

Evaluate every action in the vector from left to right and ignore result

sequenceA :: (Vector v a, Vector v (f a), Applicative f) => v (f a) -> f (v a) Source #

Analog of sequenceA from Traversable.

traverse :: (Vector v a, Vector v b, Applicative f) => (a -> f b) -> v a -> f (v b) Source #

Analog of traverse from Traversable.

distribute :: (Vector v a, Vector v (f a), Functor f) => f (v a) -> v (f a) Source #

collect :: (Vector v a, Vector v b, Vector v (f b), Functor f) => (a -> v b) -> f a -> v (f b) Source #

distributeM :: (Vector v a, Vector v (m a), Monad m) => m (v a) -> v (m a) Source #

collectM :: (Vector v a, Vector v b, Vector v (m b), Monad m) => (a -> v b) -> m a -> v (m b) Source #

Folding

foldl :: Vector v a => (b -> a -> b) -> b -> v a -> b Source #

Left fold over vector

foldr :: Vector v a => (a -> b -> b) -> b -> v a -> b Source #

Right fold over vector

foldl1 :: (Vector v a, Dim v ~ S n) => (a -> a -> a) -> v a -> a Source #

Left fold over vector

fold :: (Vector v m, Monoid m) => v m -> m Source #

Combine the elements of a structure using a monoid. Similar to fold

foldMap :: (Vector v a, Monoid m) => (a -> m) -> v a -> m Source #

Map each element of the structure to a monoid, and combine the results. Similar to foldMap

ifoldl :: Vector v a => (b -> Int -> a -> b) -> b -> v a -> b Source #

Left fold over vector. Function is applied to each element and its index.

ifoldr :: Vector v a => (Int -> a -> b -> b) -> b -> v a -> b Source #

Right fold over vector

foldM :: (Vector v a, Monad m) => (b -> a -> m b) -> b -> v a -> m b Source #

Monadic fold over vector.

ifoldM :: (Vector v a, Monad m) => (b -> Int -> a -> m b) -> b -> v a -> m b Source #

Left monadic fold over vector. Function is applied to each element and its index.

Special folds

sum :: (Vector v a, Num a) => v a -> a Source #

Sum all elements in the vector.

maximum :: (Vector v a, Dim v ~ S n, Ord a) => v a -> a Source #

Maximal element of vector.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec3)
>>> let x = mk3 1 2 3 :: Vec3 Int
>>> maximum x
3

minimum :: (Vector v a, Dim v ~ S n, Ord a) => v a -> a Source #

Minimal element of vector.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec3)
>>> let x = mk3 1 2 3 :: Vec3 Int
>>> minimum x
1

and :: Vector v Bool => v Bool -> Bool Source #

Conjunction of all elements of a vector.

or :: Vector v Bool => v Bool -> Bool Source #

Disjunction of all elements of a vector.

all :: Vector v a => (a -> Bool) -> v a -> Bool Source #

Determines whether all elements of vector satisfy predicate.

any :: Vector v a => (a -> Bool) -> v a -> Bool Source #

Determines whether any of element of vector satisfy predicate.

find :: Vector v a => (a -> Bool) -> v a -> Maybe a Source #

The find function takes a predicate and a vector and returns the leftmost element of the vector matching the predicate, or Nothing if there is no such element.

Zips

zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> v a -> v b -> v c Source #

Zip two vector together using function.

Examples:

>>> import Data.Vector.Fixed.Boxed (Vec3)
>>> let b0 = basis 0 :: Vec3 Int
>>> let b1 = basis 1 :: Vec3 Int
>>> let b2 = basis 2 :: Vec3 Int
>>> let vplus x y = zipWith (+) x y
>>> vplus b0 b1
fromList [1,1,0]
>>> vplus b0 b2
fromList [1,0,1]
>>> vplus b1 b2
fromList [0,1,1]

zipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (a -> b -> c -> d) -> v a -> v b -> v c -> v d Source #

Zip three vector together

zipWithM :: (Vector v a, Vector v b, Vector v c, Monad m) => (a -> b -> m c) -> v a -> v b -> m (v c) Source #

Zip two vector together using monadic function.

zipWithM_ :: (Vector v a, Vector v b, Monad m) => (a -> b -> m c) -> v a -> v b -> m () Source #

Zip two vector elementwise using monadic function and discard result

izipWith :: (Vector v a, Vector v b, Vector v c) => (Int -> a -> b -> c) -> v a -> v b -> v c Source #

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

izipWith3 :: (Vector v a, Vector v b, Vector v c, Vector v d) => (Int -> a -> b -> c -> d) -> v a -> v b -> v c -> v d Source #

Zip three vector together

izipWithM :: (Vector v a, Vector v b, Vector v c, Monad m) => (Int -> a -> b -> m c) -> v a -> v b -> m (v c) Source #

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

izipWithM_ :: (Vector v a, Vector v b, Vector v c, Monad m, Vector v (m c)) => (Int -> a -> b -> m c) -> v a -> v b -> m () Source #

Zip two vector elementwise using monadic function and discard result

Storable methods

Default implementation of methods for Storable type class assumes that individual elements of vector are stored as N-element array.

defaultAlignemnt :: forall a v. Storable a => v a -> Int Source #

Default implementation of alignment for Storable type class for fixed vectors.

defaultSizeOf :: forall a v. (Storable a, Vector v a) => v a -> Int Source #

Default implementation of sizeOf for Storable type class for fixed vectors

defaultPeek :: (Storable a, Vector v a) => Ptr (v a) -> IO (v a) Source #

Default implementation of peek for Storable type class for fixed vector

defaultPoke :: (Storable a, Vector v a) => Ptr (v a) -> v a -> IO () Source #

Default implementation of poke for Storable type class for fixed vector

Conversion

convert :: (Vector v a, Vector w a, Dim v ~ Dim w) => v a -> w a Source #

Convert between different vector types

toList :: Vector v a => v a -> [a] Source #

Convert vector to the list

fromList :: Vector v a => [a] -> v a Source #

Create vector form list. Will throw error if list is shorter than resulting vector.

fromList' :: Vector v a => [a] -> v a Source #

Create vector form list. Will throw error if list has different length from resulting vector.

fromListM :: Vector v a => [a] -> Maybe (v a) Source #

Create vector form list. Will return Nothing if list has different length from resulting vector.

fromFoldable :: (Vector v a, Foldable f) => f a -> Maybe (v a) Source #

Create vector from Foldable data type. Will return Nothing if data type different number of elements that resulting vector.

Data types

data VecList n a where Source #

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

Constructors

Nil :: VecList Z a 
Cons :: a -> VecList n a -> VecList (S n) a 

Instances

Arity n => VectorN VecList n a Source # 
Arity n => Functor (VecList n) Source # 

Methods

fmap :: (a -> b) -> VecList n a -> VecList n b #

(<$) :: a -> VecList n b -> VecList n a #

Arity n => Applicative (VecList n) Source # 

Methods

pure :: a -> VecList n a #

(<*>) :: VecList n (a -> b) -> VecList n a -> VecList n b #

(*>) :: VecList n a -> VecList n b -> VecList n b #

(<*) :: VecList n a -> VecList n b -> VecList n a #

Arity n => Foldable (VecList n) Source # 

Methods

fold :: Monoid m => VecList n m -> m #

foldMap :: Monoid m => (a -> m) -> VecList n a -> m #

foldr :: (a -> b -> b) -> b -> VecList n a -> b #

foldr' :: (a -> b -> b) -> b -> VecList n a -> b #

foldl :: (b -> a -> b) -> b -> VecList n a -> b #

foldl' :: (b -> a -> b) -> b -> VecList n a -> b #

foldr1 :: (a -> a -> a) -> VecList n a -> a #

foldl1 :: (a -> a -> a) -> VecList n a -> a #

toList :: VecList n a -> [a] #

null :: VecList n a -> Bool #

length :: VecList n a -> Int #

elem :: Eq a => a -> VecList n a -> Bool #

maximum :: Ord a => VecList n a -> a #

minimum :: Ord a => VecList n a -> a #

sum :: Num a => VecList n a -> a #

product :: Num a => VecList n a -> a #

Arity n => Traversable (VecList n) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> VecList n a -> f (VecList n b) #

sequenceA :: Applicative f => VecList n (f a) -> f (VecList n a) #

mapM :: Monad m => (a -> m b) -> VecList n a -> m (VecList n b) #

sequence :: Monad m => VecList n (m a) -> m (VecList n a) #

Arity n => Vector (VecList n) a Source # 

Methods

construct :: Fun (Dim (VecList n)) a (VecList n a) Source #

inspect :: VecList n a -> Fun (Dim (VecList n)) a b -> b Source #

basicIndex :: VecList n a -> Int -> a Source #

(Eq a, Arity n) => Eq (VecList n a) Source # 

Methods

(==) :: VecList n a -> VecList n a -> Bool #

(/=) :: VecList n a -> VecList n a -> Bool #

(Ord a, Arity n) => Ord (VecList n a) Source # 

Methods

compare :: VecList n a -> VecList n a -> Ordering #

(<) :: VecList n a -> VecList n a -> Bool #

(<=) :: VecList n a -> VecList n a -> Bool #

(>) :: VecList n a -> VecList n a -> Bool #

(>=) :: VecList n a -> VecList n a -> Bool #

max :: VecList n a -> VecList n a -> VecList n a #

min :: VecList n a -> VecList n a -> VecList n a #

(Show a, Arity n) => Show (VecList n a) Source # 

Methods

showsPrec :: Int -> VecList n a -> ShowS #

show :: VecList n a -> String #

showList :: [VecList n a] -> ShowS #

(Arity n, Monoid a) => Monoid (VecList n a) Source # 

Methods

mempty :: VecList n a #

mappend :: VecList n a -> VecList n a -> VecList n a #

mconcat :: [VecList n a] -> VecList n a #

(Storable a, Arity n) => Storable (VecList n a) Source # 

Methods

sizeOf :: VecList n a -> Int #

alignment :: VecList n a -> Int #

peekElemOff :: Ptr (VecList n a) -> Int -> IO (VecList n a) #

pokeElemOff :: Ptr (VecList n a) -> Int -> VecList n a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (VecList n a) #

pokeByteOff :: Ptr b -> Int -> VecList n a -> IO () #

peek :: Ptr (VecList n a) -> IO (VecList n a) #

poke :: Ptr (VecList n a) -> VecList n a -> IO () #

(Arity n, NFData a) => NFData (VecList n a) Source # 

Methods

rnf :: VecList n a -> () #

type Dim (VecList n) Source # 
type Dim (VecList n) = n

newtype Only a Source #

Single-element tuple.

Constructors

Only a 

Instances

Functor Only Source # 

Methods

fmap :: (a -> b) -> Only a -> Only b #

(<$) :: a -> Only b -> Only a #

Foldable Only Source # 

Methods

fold :: Monoid m => Only m -> m #

foldMap :: Monoid m => (a -> m) -> Only a -> m #

foldr :: (a -> b -> b) -> b -> Only a -> b #

foldr' :: (a -> b -> b) -> b -> Only a -> b #

foldl :: (b -> a -> b) -> b -> Only a -> b #

foldl' :: (b -> a -> b) -> b -> Only a -> b #

foldr1 :: (a -> a -> a) -> Only a -> a #

foldl1 :: (a -> a -> a) -> Only a -> a #

toList :: Only a -> [a] #

null :: Only a -> Bool #

length :: Only a -> Int #

elem :: Eq a => a -> Only a -> Bool #

maximum :: Ord a => Only a -> a #

minimum :: Ord a => Only a -> a #

sum :: Num a => Only a -> a #

product :: Num a => Only a -> a #

Traversable Only Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Only a -> f (Only b) #

sequenceA :: Applicative f => Only (f a) -> f (Only a) #

mapM :: Monad m => (a -> m b) -> Only a -> m (Only b) #

sequence :: Monad m => Only (m a) -> m (Only a) #

Vector Only a Source # 

Methods

construct :: Fun (Dim Only) a (Only a) Source #

inspect :: Only a -> Fun (Dim Only) a b -> b Source #

basicIndex :: Only a -> Int -> a Source #

Eq a => Eq (Only a) Source # 

Methods

(==) :: Only a -> Only a -> Bool #

(/=) :: Only a -> Only a -> Bool #

Data a => Data (Only a) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Only a -> c (Only a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Only a) #

toConstr :: Only a -> Constr #

dataTypeOf :: Only a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Only a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Only a)) #

gmapT :: (forall b. Data b => b -> b) -> Only a -> Only a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Only a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Only a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Only a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Only a -> m (Only a) #

Ord a => Ord (Only a) Source # 

Methods

compare :: Only a -> Only a -> Ordering #

(<) :: Only a -> Only a -> Bool #

(<=) :: Only a -> Only a -> Bool #

(>) :: Only a -> Only a -> Bool #

(>=) :: Only a -> Only a -> Bool #

max :: Only a -> Only a -> Only a #

min :: Only a -> Only a -> Only a #

Show a => Show (Only a) Source # 

Methods

showsPrec :: Int -> Only a -> ShowS #

show :: Only a -> String #

showList :: [Only a] -> ShowS #

Monoid a => Monoid (Only a) Source # 

Methods

mempty :: Only a #

mappend :: Only a -> Only a -> Only a #

mconcat :: [Only a] -> Only a #

Storable a => Storable (Only a) Source # 

Methods

sizeOf :: Only a -> Int #

alignment :: Only a -> Int #

peekElemOff :: Ptr (Only a) -> Int -> IO (Only a) #

pokeElemOff :: Ptr (Only a) -> Int -> Only a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Only a) #

pokeByteOff :: Ptr b -> Int -> Only a -> IO () #

peek :: Ptr (Only a) -> IO (Only a) #

poke :: Ptr (Only a) -> Only a -> IO () #

NFData a => NFData (Only a) Source # 

Methods

rnf :: Only a -> () #

type Dim Only Source # 
type Dim Only = S Z

data Empty a Source #

Empty tuple.

Constructors

Empty 

Instances

Functor Empty Source # 

Methods

fmap :: (a -> b) -> Empty a -> Empty b #

(<$) :: a -> Empty b -> Empty a #

Foldable Empty Source # 

Methods

fold :: Monoid m => Empty m -> m #

foldMap :: Monoid m => (a -> m) -> Empty a -> m #

foldr :: (a -> b -> b) -> b -> Empty a -> b #

foldr' :: (a -> b -> b) -> b -> Empty a -> b #

foldl :: (b -> a -> b) -> b -> Empty a -> b #

foldl' :: (b -> a -> b) -> b -> Empty a -> b #

foldr1 :: (a -> a -> a) -> Empty a -> a #

foldl1 :: (a -> a -> a) -> Empty a -> a #

toList :: Empty a -> [a] #

null :: Empty a -> Bool #

length :: Empty a -> Int #

elem :: Eq a => a -> Empty a -> Bool #

maximum :: Ord a => Empty a -> a #

minimum :: Ord a => Empty a -> a #

sum :: Num a => Empty a -> a #

product :: Num a => Empty a -> a #

Traversable Empty Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Empty a -> f (Empty b) #

sequenceA :: Applicative f => Empty (f a) -> f (Empty a) #

mapM :: Monad m => (a -> m b) -> Empty a -> m (Empty b) #

sequence :: Monad m => Empty (m a) -> m (Empty a) #

Vector Empty a Source # 

Methods

construct :: Fun (Dim Empty) a (Empty a) Source #

inspect :: Empty a -> Fun (Dim Empty) a b -> b Source #

basicIndex :: Empty a -> Int -> a Source #

Data a => Data (Empty a) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Empty a -> c (Empty a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Empty a) #

toConstr :: Empty a -> Constr #

dataTypeOf :: Empty a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Empty a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Empty a)) #

gmapT :: (forall b. Data b => b -> b) -> Empty a -> Empty a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Empty a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Empty a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Empty a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Empty a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Empty a -> m (Empty a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Empty a -> m (Empty a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Empty a -> m (Empty a) #

NFData (Empty a) Source # 

Methods

rnf :: Empty a -> () #

type Dim Empty Source # 
type Dim Empty = Z

Tuple synonyms

type Tuple2 a = (a, a) Source #

type Tuple3 a = (a, a, a) Source #

type Tuple4 a = (a, a, a, a) Source #

type Tuple5 a = (a, a, a, a, a) Source #