Stability | experimental |
---|---|
Maintainer | conal@conal.net |
Safe Haskell | None |
Experiment in length-typed vectors
- module TypeUnary.Nat
- data Vec where
- unConsV :: Vec (S n) a -> (a, Vec n a)
- headV :: Vec (S n) a -> a
- tailV :: Vec (S n) a -> Vec n a
- joinV :: Vec n (Vec n a) -> Vec n a
- (<+>) :: Vec m a -> Vec n a -> Vec (m :+: n) a
- indices :: IsNat n => Vec n (Index n)
- iota :: (IsNat n, Num a, Enum a) => Vec n a
- type Vec0 = Vec N0
- type Vec1 = Vec N1
- type Vec2 = Vec N2
- type Vec3 = Vec N3
- type Vec4 = Vec N4
- type Vec5 = Vec N5
- type Vec6 = Vec N6
- type Vec7 = Vec N7
- type Vec8 = Vec N8
- type Vec9 = Vec N9
- type Vec10 = Vec N10
- type Vec11 = Vec N11
- type Vec12 = Vec N12
- type Vec13 = Vec N13
- type Vec14 = Vec N14
- type Vec15 = Vec N15
- type Vec16 = Vec N16
- vec1 :: a -> Vec1 a
- vec2 :: a -> a -> Vec2 a
- vec3 :: a -> a -> a -> Vec3 a
- vec4 :: a -> a -> a -> a -> Vec4 a
- vec5 :: a -> a -> a -> a -> a -> Vec5 a
- vec6 :: a -> a -> a -> a -> a -> a -> Vec6 a
- vec7 :: a -> a -> a -> a -> a -> a -> a -> Vec7 a
- vec8 :: a -> a -> a -> a -> a -> a -> a -> a -> Vec8 a
- un1 :: Vec1 a -> a
- un2 :: Vec2 a -> (a, a)
- un3 :: Vec3 a -> (a, a, a)
- un4 :: Vec4 a -> (a, a, a, a)
- get :: Index n -> Vec n a -> a
- get0 :: Vec (N1 :+: n) a -> a
- get1 :: Vec (N2 :+: n) a -> a
- get2 :: Vec (N3 :+: n) a -> a
- get3 :: Vec (N4 :+: n) a -> a
- update :: Index n -> (a -> a) -> Vec n a -> Vec n a
- set :: Index n -> a -> Vec n a -> Vec n a
- set0 :: a -> Vec (N1 :+: n) a -> Vec (N1 :+: n) a
- set1 :: a -> Vec (N2 :+: n) a -> Vec (N2 :+: n) a
- set2 :: a -> Vec (N3 :+: n) a -> Vec (N3 :+: n) a
- set3 :: a -> Vec (N4 :+: n) a -> Vec (N4 :+: n) a
- getI :: (IsNat n, Show i, Integral i) => i -> Vec n a -> a
- setI :: (IsNat n, Show i, Integral i) => i -> a -> Vec n a -> Vec n a
- flattenV :: IsNat n => Vec n (Vec m a) -> Vec (n :*: m) a
- chunkV :: (IsNat n, IsNat m) => Vec (n :*: m) a -> Vec n (Vec m a)
- swizzle :: Vec n (Index m) -> Vec m a -> Vec n a
- split :: IsNat n => Vec (n :+: m) a -> (Vec n a, Vec m a)
- deleteV :: Eq a => a -> Vec (S n) a -> Vec n a
- elemsV :: IsNat n => [a] -> Vec n a
- zipV :: Vec n a -> Vec n b -> Vec n (a, b)
- zipWithV :: (a -> b -> c) -> Vec n a -> Vec n b -> Vec n c
- unzipV :: Vec n (a, b) -> (Vec n a, Vec n b)
- zipV3 :: Vec n a -> Vec n b -> Vec n c -> Vec n (a, b, c)
- zipWithV3 :: (a -> b -> c -> d) -> Vec n a -> Vec n b -> Vec n c -> Vec n d
- unzipV3 :: Vec n (a, b, c) -> (Vec n a, Vec n b, Vec n c)
- transpose :: IsNat n => Vec m (Vec n a) -> Vec n (Vec m a)
- cross :: Vec m a -> Vec n b -> Vec m (Vec n (a, b))
- class ToVec c n a where
Documentation
module TypeUnary.Nat
Vectors
Vectors with type-determined length, having empty vector (ZVec
) and
vector cons ('(:<)').
Typeable2 Vec | |
IsNat n => Monad (Vec n) | |
Functor (Vec n) | |
IsNat n => Applicative (Vec n) | |
Foldable (Vec n) | |
Traversable (Vec n) | |
(IsNat n, Enum applicative_arg) => Enum (Vec n applicative_arg) | |
Eq a => Eq (Vec n a) | |
(IsNat n, Floating applicative_arg) => Floating (Vec n applicative_arg) | |
(IsNat n, Fractional applicative_arg) => Fractional (Vec n applicative_arg) | |
(IsNat n, Integral applicative_arg) => Integral (Vec n applicative_arg) | |
(IsNat n, Num applicative_arg) => Num (Vec n applicative_arg) | |
Ord a => Ord (Vec n a) | |
(IsNat n, Num applicative_arg, Ord applicative_arg) => Real (Vec n applicative_arg) | |
(IsNat n, RealFloat applicative_arg) => RealFloat (Vec n applicative_arg) | |
(IsNat n, RealFrac applicative_arg) => RealFrac (Vec n applicative_arg) | |
Show a => Show (Vec n a) | |
(IsNat n, Monoid a) => Monoid (Vec n a) | |
(IsNat n, Storable a) => Storable (Vec n a) | |
(IsNat n, Num a) => VectorSpace (Vec n a) | |
(IsNat n, Num a) => InnerSpace (Vec n a) | |
(IsNat n, Num a) => AdditiveGroup (Vec n a) | |
Newtype (Vec Z a) () | |
ToVec (Vec n a) n a | |
Newtype (Vec (S n) a) (a, Vec n a) |
iota :: (IsNat n, Num a, Enum a) => Vec n aSource
Vector of ints from 0 to n-1. Named for APL iota operation (but 0 based).
get :: Index n -> Vec n a -> aSource
Extract a vector element, taking a proof that the index is within bounds.
update :: Index n -> (a -> a) -> Vec n a -> Vec n aSource
Update a vector element, taking a proof that the index is within bounds.
set :: Index n -> a -> Vec n a -> Vec n aSource
Replace a vector element, taking a proof that the index is within bounds.
getI :: (IsNat n, Show i, Integral i) => i -> Vec n a -> aSource
Variant of get
in which the index size is checked at run-time
instead of compile-time.
setI :: (IsNat n, Show i, Integral i) => i -> a -> Vec n a -> Vec n aSource
Variant of set
in which the index size is checked at run-time
instead of compile-time.
flattenV :: IsNat n => Vec n (Vec m a) -> Vec (n :*: m) aSource
Flatten a vector of vectors (a 2D array) into a vector
chunkV :: (IsNat n, IsNat m) => Vec (n :*: m) a -> Vec n (Vec m a)Source
Chunk a vector into a vector of vectors (a 2D array)
swizzle :: Vec n (Index m) -> Vec m a -> Vec n aSource
Swizzling. Extract multiple elements simultaneously.
deleteV :: Eq a => a -> Vec (S n) a -> Vec n aSource
Delete exactly one occurrence of an element from a vector, raising an error if the element isn't present.
elemsV :: IsNat n => [a] -> Vec n aSource
Convert a list into a vector. Error if the list is too short or too long
zipV :: Vec n a -> Vec n b -> Vec n (a, b)Source
Zip two vectors into one. Like
, but the former requires
liftA2
'(,)'IsNat n
.
zipWithV :: (a -> b -> c) -> Vec n a -> Vec n b -> Vec n cSource
Unzip one vector into two. Like liftA2
, but the former requires
IsNat n
.
zipV3 :: Vec n a -> Vec n b -> Vec n c -> Vec n (a, b, c)Source
Zip three vectors into one. Like
, but the former requires
liftA3
'(,)'IsNat n
.
zipWithV3 :: (a -> b -> c -> d) -> Vec n a -> Vec n b -> Vec n c -> Vec n dSource
Unzip one vector into two. Like liftA2
, but the former requires
IsNat n
.
unzipV3 :: Vec n (a, b, c) -> (Vec n a, Vec n b, Vec n c)Source
Unzip a vector of pairs into a pair of vectors
transpose :: IsNat n => Vec m (Vec n a) -> Vec n (Vec m a)Source
Matrix transposition. Specialization of sequenceA
.