Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- type family Dim (v :: * -> *) :: Nat
- class Arity (Dim v) => Vector v a where
- class (Vector (v n) a, Dim (v n) ~ n) => VectorN v n a
- type Arity n = (ArityPeano (Peano n), KnownNat n, Peano (n + 1) ~ 'S (Peano n))
- newtype Fun n a b = Fun {}
- length :: forall v a. KnownNat (Dim v) => v a -> Int
- mk0 :: (Vector v a, Dim v ~ 0) => v a
- mk1 :: (Vector v a, Dim v ~ 1) => a -> v a
- mk2 :: (Vector v a, Dim v ~ 2) => a -> a -> v a
- mk3 :: (Vector v a, Dim v ~ 3) => a -> a -> a -> v a
- mk4 :: (Vector v a, Dim v ~ 4) => a -> a -> a -> a -> v a
- mk5 :: (Vector v a, Dim v ~ 5) => a -> a -> a -> a -> a -> v a
- mk6 :: (Vector v a, Dim v ~ 6) => a -> a -> a -> a -> a -> a -> v a
- mk7 :: (Vector v a, Dim v ~ 7) => a -> a -> a -> a -> a -> a -> a -> v a
- mk8 :: (Vector v a, Dim v ~ 8) => a -> a -> a -> a -> a -> a -> a -> a -> v a
- mkN :: forall proxy v a. Vector v a => proxy (v a) -> Fn (Peano (Dim v)) a (v a)
- pattern V2 :: (Vector v a, Dim v ~ 2) => a -> a -> v a
- pattern V3 :: (Vector v a, Dim v ~ 3) => a -> a -> a -> v a
- pattern V4 :: (Vector v a, Dim v ~ 4) => a -> a -> a -> a -> v a
- data ContVec n a
- empty :: ContVec 0 a
- vector :: (Vector v a, Dim v ~ n) => ContVec n a -> v a
- cvec :: (Vector v a, Dim v ~ n) => v a -> ContVec n a
- replicate :: Vector v a => a -> v a
- replicateM :: (Vector v a, Applicative f) => f a -> f (v a)
- generate :: Vector v a => (Int -> a) -> v a
- generateM :: (Applicative f, Vector v a) => (Int -> f a) -> f (v a)
- unfoldr :: Vector v a => (b -> (a, b)) -> b -> v a
- basis :: (Vector v a, Num a) => Int -> v a
- head :: (Vector v a, 1 <= Dim v) => v a -> a
- tail :: (Vector v a, Vector w a, Dim v ~ (Dim w + 1)) => v a -> w a
- cons :: (Vector v a, Vector w a, Dim w ~ (Dim v + 1)) => a -> v a -> w a
- snoc :: (Vector v a, Vector w a, Dim w ~ (Dim v + 1)) => a -> v a -> w a
- concat :: (Vector v a, Vector u a, Vector w a, (Dim v + Dim u) ~ Dim w, Peano (Dim v + Dim u) ~ Add (Peano (Dim v)) (Peano (Dim u))) => v a -> u a -> w a
- reverse :: Vector v a => v a -> v a
- (!) :: Vector v a => v a -> Int -> a
- index :: (Vector v a, KnownNat k, (k + 1) <= Dim v) => v a -> proxy k -> a
- set :: (Vector v a, KnownNat k, (k + 1) <= Dim v) => proxy k -> a -> v a -> v a
- element :: (Vector v a, Functor f) => Int -> (a -> f a) -> v a -> f (v a)
- elementTy :: (Vector v a, KnownNat k, (k + 1) <= Dim v, Functor f) => proxy k -> (a -> f a) -> v a -> f (v a)
- eq :: (Vector v a, Eq a) => v a -> v a -> Bool
- ord :: (Vector v a, Ord a) => v a -> v a -> Ordering
- map :: (Vector v a, Vector v b) => (a -> b) -> v a -> v b
- mapM :: (Vector v a, Vector v b, Applicative f) => (a -> f b) -> v a -> f (v b)
- mapM_ :: (Vector v a, Applicative f) => (a -> f b) -> v a -> f ()
- imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> v a -> v b
- imapM :: (Vector v a, Vector v b, Applicative f) => (Int -> a -> f b) -> v a -> f (v b)
- imapM_ :: (Vector v a, Applicative f) => (Int -> a -> f b) -> v a -> f ()
- scanl :: (Vector v a, Vector w b, Dim w ~ (Dim v + 1)) => (b -> a -> b) -> b -> v a -> w b
- scanl1 :: Vector v a => (a -> a -> a) -> v a -> v a
- sequence :: (Vector v a, Vector v (f a), Applicative f) => v (f a) -> f (v a)
- sequence_ :: (Vector v (f a), Applicative f) => v (f a) -> f ()
- sequenceA :: (Vector v a, Vector v (f a), Applicative f) => v (f a) -> f (v a)
- traverse :: (Vector v a, Vector v b, Applicative f) => (a -> f b) -> v a -> f (v b)
- distribute :: (Vector v a, Vector v (f a), Functor f) => f (v a) -> v (f a)
- collect :: (Vector v a, Vector v b, Vector v (f b), Functor f) => (a -> v b) -> f a -> v (f b)
- foldl :: Vector v a => (b -> a -> b) -> b -> v a -> b
- foldr :: Vector v a => (a -> b -> b) -> b -> v a -> b
- foldl1 :: (Vector v a, 1 <= Dim v) => (a -> a -> a) -> v a -> a
- fold :: (Vector v m, Monoid m) => v m -> m
- foldMap :: (Vector v a, Monoid m) => (a -> m) -> v a -> m
- ifoldl :: Vector v a => (b -> Int -> a -> b) -> b -> v a -> b
- ifoldr :: Vector v a => (Int -> a -> b -> b) -> b -> v a -> b
- foldM :: (Vector v a, Monad m) => (b -> a -> m b) -> b -> v a -> m b
- ifoldM :: (Vector v a, Monad m) => (b -> Int -> a -> m b) -> b -> v a -> m b
- sum :: (Vector v a, Num a) => v a -> a
- maximum :: (Vector v a, 1 <= Dim v, Ord a) => v a -> a
- minimum :: (Vector v a, 1 <= Dim v, Ord a) => v a -> a
- and :: Vector v Bool => v Bool -> Bool
- or :: Vector v Bool => v Bool -> Bool
- all :: Vector v a => (a -> Bool) -> v a -> Bool
- any :: Vector v a => (a -> Bool) -> v a -> Bool
- find :: Vector v a => (a -> Bool) -> v a -> Maybe a
- zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> v a -> v b -> v c
- 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
- zipWithM :: (Vector v a, Vector v b, Vector v c, Applicative f) => (a -> b -> f c) -> v a -> v b -> f (v c)
- zipWithM_ :: (Vector v a, Vector v b, Applicative f) => (a -> b -> f c) -> v a -> v b -> f ()
- izipWith :: (Vector v a, Vector v b, Vector v c) => (Int -> a -> b -> c) -> v a -> v b -> v c
- 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
- izipWithM :: (Vector v a, Vector v b, Vector v c, Applicative f) => (Int -> a -> b -> f c) -> v a -> v b -> f (v c)
- izipWithM_ :: (Vector v a, Vector v b, Vector v c, Applicative f, Vector v (f c)) => (Int -> a -> b -> f c) -> v a -> v b -> f ()
- defaultAlignemnt :: forall a v. Storable a => v a -> Int
- defaultSizeOf :: forall a v. (Storable a, Vector v a) => v a -> Int
- defaultPeek :: (Storable a, Vector v a) => Ptr (v a) -> IO (v a)
- defaultPoke :: (Storable a, Vector v a) => Ptr (v a) -> v a -> IO ()
- defaultRnf :: (NFData a, Vector v a) => v a -> ()
- convert :: (Vector v a, Vector w a, Dim v ~ Dim w) => v a -> w a
- toList :: Vector v a => v a -> [a]
- fromList :: Vector v a => [a] -> v a
- fromList' :: Vector v a => [a] -> v a
- fromListM :: Vector v a => [a] -> Maybe (v a)
- fromFoldable :: (Vector v a, Foldable f) => f a -> Maybe (v a)
- newtype VecList (n :: Nat) a = VecList (VecPeano (Peano n) a)
- data VecPeano (n :: PeanoNum) a where
- newtype Only a = Only a
- data Empty a = Empty
- type Tuple2 a = (a, a)
- type Tuple3 a = (a, a, a)
- type Tuple4 a = (a, a, a, a)
- type Tuple5 a = (a, a, a, a, a)
Vector type class
Vector size
type family Dim (v :: * -> *) :: Nat Source #
Size of vector expressed as type-level natural.
Instances
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
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
construct :: Fun (Peano (Dim v)) a (v a) Source #
N-ary function for creation of vectors.
inspect :: v a -> Fun (Peano (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
Vector Complex a Source # | |
Vector Identity a Source # | |
Vector Only 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 (Proxy :: Type -> Type) a Source # | |
Arity n => Vector (ContVec n) a Source # | |
Vector (Empty :: Type -> Type) a Source # | |
Arity n => Vector (VecList n) a Source # | |
Arity n => Vector (Vec n) a Source # | |
(Arity n, Prim a) => Vector (Vec n) a Source # | |
(Arity n, Storable a) => Vector (Vec n) a Source # | |
Unbox n a => Vector (Vec n) a Source # | |
(b ~ a, c ~ a) => Vector ((,,) b c) a Source # | |
(b ~ a, c ~ a, d ~ a) => Vector ((,,,) b c d) a Source # | |
(b ~ a, c ~ a, d ~ a, e ~ a) => Vector ((,,,,) b c d e) a 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 # | |
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 # | |
Defined in Data.Vector.Fixed.Cont | |
Arity n => VectorN VecList n a Source # | |
Defined in Data.Vector.Fixed | |
Arity n => VectorN Vec n a Source # | |
Defined in Data.Vector.Fixed.Boxed | |
(Arity n, Prim a) => VectorN Vec n a Source # | |
Defined in Data.Vector.Fixed.Primitive | |
(Arity n, Storable a) => VectorN Vec n a Source # | |
Defined in Data.Vector.Fixed.Storable | |
Unbox n a => VectorN Vec n a Source # | |
Defined in Data.Vector.Fixed.Unboxed |
type Arity n = (ArityPeano (Peano n), KnownNat n, Peano (n + 1) ~ 'S (Peano n)) Source #
Type class for type level number for which we can defined operations over N-ary functions.
Newtype wrapper which is used to make Fn
injective. It's also a
reader monad.
Instances
ArityPeano n => Monad (Fun n a) Source # | |
ArityPeano n => Functor (Fun n a) Source # | |
ArityPeano n => Applicative (Fun n a) Source # | |
length :: forall v a. KnownNat (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')
Alternatively one could use mkN
. See its documentation for
examples.
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)) = ...
For small vectors pattern synonyms V2
, V3$,
V4@ are provided
that use same trick internally.
Constructors for vectors with small dimensions.
mkN :: forall proxy v a. Vector v a => proxy (v a) -> Fn (Peano (Dim v)) a (v a) Source #
N-ary constructor. Despite scary signature it's just N-ary function with additional type parameter which is used to fix type of vector being constructed. It could be used as:
v = mkN (Proxy :: Proxy (Int,Int,Int)) 1 2 3
or using TypeApplications
syntax:
v = mkN (Proxy @ (Int,Int,Int)) 1 2 3
or if type of v
is fixed elsewhere
v = mkN [v] 1 2 3
Pattern for low-dimension vectors
Continuation-based vectors
Vector represented as continuation. Alternative wording: it's Church encoded N-element vector.
Instances
Arity n => VectorN ContVec n a Source # | |
Defined in Data.Vector.Fixed.Cont | |
Arity n => Functor (ContVec n) Source # | |
Arity n => Applicative (ContVec n) Source # | |
Arity n => Foldable (ContVec n) Source # | |
Defined in Data.Vector.Fixed.Cont fold :: Monoid m => ContVec n m -> m # foldMap :: Monoid m => (a -> m) -> ContVec n a -> 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] # 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 # | |
Arity n => Traversable (ContVec n) Source # | |
Arity n => Vector (ContVec n) a Source # | |
type Dim (ContVec n) Source # | |
Defined in Data.Vector.Fixed.Cont |
cvec :: (Vector v a, Dim v ~ n) => v a -> ContVec n a Source #
Convert regular vector to continuation based one.
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, Applicative f) => f a -> f (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 :: (Applicative f, Vector v a) => (Int -> f a) -> f (v a) Source #
Generate vector from monadic function which maps element's index to its value.
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, 1 <= Dim v) => 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 ~ (Dim w + 1)) => 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, Dim w ~ (Dim v + 1)) => a -> v a -> w a Source #
Cons element to the vector
snoc :: (Vector v a, Vector w a, Dim w ~ (Dim v + 1)) => a -> v a -> w a Source #
Append element to the vector
concat :: (Vector v a, Vector u a, Vector w a, (Dim v + Dim u) ~ Dim w, Peano (Dim v + Dim u) ~ Add (Peano (Dim v)) (Peano (Dim u))) => v a -> u a -> w a Source #
Indexing & lenses
(!) :: 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, KnownNat k, (k + 1) <= Dim v) => v a -> proxy k -> a Source #
Get element from vector at statically known index
set :: (Vector v a, KnownNat k, (k + 1) <= Dim v) => proxy 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, KnownNat k, (k + 1) <= Dim v, Functor f) => proxy 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
Maps
mapM :: (Vector v a, Vector v b, Applicative f) => (a -> f b) -> v a -> f (v b) Source #
Effectful map over vector.
mapM_ :: (Vector v a, Applicative f) => (a -> f b) -> v a -> f () 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, Applicative f) => (Int -> a -> f b) -> v a -> f (v b) Source #
Apply monadic function to every element of the vector and its index.
imapM_ :: (Vector v a, Applicative f) => (Int -> a -> f b) -> v a -> f () 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 ~ (Dim v + 1)) => (b -> a -> b) -> b -> v a -> w b Source #
Left scan over vector
sequence :: (Vector v a, Vector v (f a), Applicative f) => v (f a) -> f (v a) Source #
Evaluate every action in the vector from left to right.
sequence_ :: (Vector v (f a), Applicative f) => v (f a) -> f () 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
.
collect :: (Vector v a, Vector v b, Vector v (f b), Functor f) => (a -> v b) -> f a -> v (f b) Source #
Folding
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.
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
maximum :: (Vector v a, 1 <= Dim v, 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, 1 <= Dim v, 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
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.
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, Applicative f) => (a -> b -> f c) -> v a -> v b -> f (v c) Source #
Zip two vector together using monadic function.
zipWithM_ :: (Vector v a, Vector v b, Applicative f) => (a -> b -> f c) -> v a -> v b -> f () 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, Applicative f) => (Int -> a -> b -> f c) -> v a -> v b -> f (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, Applicative f, Vector v (f c)) => (Int -> a -> b -> f c) -> v a -> v b -> f () 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 #
NFData
defaultRnf :: (NFData a, Vector v a) => v a -> () Source #
Conversion
convert :: (Vector v a, Vector w a, Dim v ~ Dim w) => v a -> w a Source #
Convert between different vector types
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
newtype VecList (n :: Nat) a Source #
Type-based vector with statically known length parametrized by GHC's type naturals
Instances
data VecPeano (n :: PeanoNum) a where Source #
Standard GADT-based vector with statically known length parametrized by Peano numbers.
Single-element tuple.
Only a |
Instances
Functor Only Source # | |
Foldable Only Source # | |
Defined in Data.Vector.Fixed fold :: Monoid m => Only m -> m # foldMap :: Monoid m => (a -> m) -> Only a -> 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 # elem :: Eq a => a -> Only a -> Bool # maximum :: Ord a => Only a -> a # | |
Traversable Only Source # | |
Vector Only a Source # | |
Eq a => Eq (Only a) Source # | |
Data a => Data (Only a) Source # | |
Defined in Data.Vector.Fixed 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 :: forall r r'. (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 # | |
Show a => Show (Only a) Source # | |
Semigroup a => Semigroup (Only a) Source # | |
Monoid a => Monoid (Only a) Source # | |
Storable a => Storable (Only a) Source # | |
NFData a => NFData (Only a) Source # | |
Defined in Data.Vector.Fixed | |
type Dim Only Source # | |
Defined in Data.Vector.Fixed |
Empty tuple.
Instances
Functor (Empty :: Type -> Type) Source # | |
Foldable (Empty :: Type -> Type) Source # | |
Defined in Data.Vector.Fixed fold :: Monoid m => Empty m -> m # foldMap :: Monoid m => (a -> m) -> Empty a -> 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 # elem :: Eq a => a -> Empty a -> Bool # maximum :: Ord a => Empty a -> a # minimum :: Ord a => Empty a -> a # | |
Traversable (Empty :: Type -> Type) Source # | |
Vector (Empty :: Type -> Type) a Source # | |
Eq (Empty a) Source # | |
(Typeable a, Typeable k) => Data (Empty a) Source # | |
Defined in Data.Vector.Fixed 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 :: forall r r'. (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) # | |
Ord (Empty a) Source # | |
Show (Empty a) Source # | |
NFData (Empty a) Source # | |
Defined in Data.Vector.Fixed | |
type Dim (Empty :: Type -> Type) Source # | |
Defined in Data.Vector.Fixed |