Copyright | (c) Alexandre Joannou 2019-2021 |
---|---|
License | MIT |
Maintainer | alexandre.joannou@gmail.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
A blarney module for handling vectors
Synopsis
- data Vec (n :: Nat) a = Vec {
- toList :: [a]
- newVec :: forall n a. KnownNat n => Vec n a
- genVec :: forall n. KnownNat n => Vec n Integer
- fromList :: forall n a. KnownNat n => [a] -> Vec n a
- replicate :: forall n a. KnownNat n => a -> Vec n a
- replicateM :: forall n a m. (Monad m, KnownNat n) => m a -> m (Vec n a)
- genWith :: forall n a. KnownNat n => (Integer -> a) -> Vec n a
- genWithM :: forall n a m. (Monad m, KnownNat n) => (Integer -> m a) -> m (Vec n a)
- cons :: a -> Vec n a -> Vec (n + 1) a
- nil :: Vec 0 a
- append :: Vec n a -> Vec m a -> Vec (n + m) a
- concat :: Vec m (Vec n a) -> Vec (m * n) a
- select :: forall i n a. (KnownNat i, (i + 1) <= n) => Vec n a -> a
- split :: forall n n0 n1 a. (KnownNat n0, (n0 + n1) ~ n) => Vec n a -> (Vec n0 a, Vec n1 a)
- update :: Vec n a -> Int -> a -> Vec n a
- head :: 1 <= n => Vec n a -> a
- last :: 1 <= n => Vec n a -> a
- tail :: Vec (n + 1) a -> Vec n a
- init :: Vec (n + 1) a -> Vec n a
- take :: forall n m a. (KnownNat m, m <= n) => Vec n a -> Vec m a
- takeTail :: forall n m a. (KnownNat m, m <= n) => Vec n a -> Vec m a
- drop :: forall i n a. (KnownNat i, i <= n) => Vec n a -> Vec (n - i) a
- takeAt :: forall n m a. (KnownNat n, KnownNat m, m <= n) => Int -> Vec n a -> Vec m a
- rotateL :: Vec n a -> Vec n a
- rotateR :: Vec n a -> Vec n a
- rotateLBy :: Bits a => Bit m -> Vec n a -> Vec n a
- rotateRBy :: Bits a => Bit m -> Vec n a -> Vec n a
- reverse :: Vec n a -> Vec n a
- elem :: Cmp a => a -> Vec n a -> Bit 1
- any :: (a -> Bit 1) -> Vec n a -> Bit 1
- all :: (a -> Bit 1) -> Vec n a -> Bit 1
- or :: Vec n (Bit 1) -> Bit 1
- and :: Vec n (Bit 1) -> Bit 1
- countElem :: (Cmp a, 1 <= n, _) => a -> Vec n a -> Bit (Log2Ceil n + 1)
- countIf :: (1 <= n, _) => (a -> Bit 1) -> Vec n a -> Bit (Log2Ceil n + 1)
- find :: Bits a => (a -> Bit 1) -> Vec n a -> Option a
- zip :: Vec n a -> Vec n b -> Vec n (a, b)
- zip3 :: Vec n a -> Vec n b -> Vec n c -> Vec n (a, b, c)
- zip4 :: Vec n a -> Vec n b -> Vec n c -> Vec n d -> Vec n (a, b, c, d)
- unzip :: Vec n (a, b) -> (Vec n a, Vec n b)
- vectorise :: ([a] -> [b]) -> Vec n a -> Vec n b
- map :: (a -> b) -> Vec n a -> Vec n b
- mapM :: Monad m => (a -> m b) -> Vec n a -> m (Vec n b)
- mapM_ :: Monad m => (a -> m b) -> Vec n a -> m ()
- zipWith :: (a -> b -> c) -> Vec n a -> Vec n b -> Vec n c
- zipWithM :: Monad m => (a -> b -> m c) -> Vec n a -> Vec n b -> m (Vec n c)
- zipWithM_ :: Monad m => (a -> b -> m c) -> Vec n a -> Vec n b -> m ()
- zipWith3 :: (a -> b -> c -> d) -> Vec n a -> Vec n b -> Vec n c -> Vec n d
- zipWith3M :: Monad m => (a -> b -> c -> m d) -> Vec n a -> Vec n b -> Vec n c -> m (Vec n d)
- zipAny :: Vec n a -> Vec m b -> Vec (Min n m) (a, b)
- zipWithAny :: (a -> b -> c) -> Vec n a -> Vec m b -> Vec (Min n m) c
- zipWithAny3 :: (a -> b -> c -> d) -> Vec n0 a -> Vec n1 b -> Vec n2 c -> Vec (Min n0 (Min n1 n2)) d
- tree :: (a -> a -> a) -> a -> Vec n a -> a
- tree1 :: (a -> a -> a) -> Vec n a -> a
- foldr :: (a -> b -> b) -> b -> Vec n a -> b
- foldl :: (b -> a -> b) -> b -> Vec n a -> b
- foldr1 :: 1 <= n => (a -> a -> a) -> Vec n a -> a
- foldl1 :: 1 <= n => (a -> a -> a) -> Vec n a -> a
- scanr :: (a -> b -> b) -> b -> Vec n a -> Vec (n + 1) b
- sscanr :: (a -> b -> b) -> b -> Vec n a -> Vec (n + 1) b
- scanl :: (b -> a -> b) -> b -> Vec n a -> Vec (n + 1) b
- sscanl :: (b -> a -> b) -> b -> Vec n a -> Vec (n + 1) b
Vec
data Vec (n :: Nat) a Source #
Vec
type
Instances
Functor (Vec n) # | |
Generic (Vec n a) # | |
(KnownNat n, Bits a) => Bits (Vec n a) # | |
FShow a => FShow (Vec n a) # | |
(KnownNat n, Interface a) => Interface (Vec n a) # | |
Lookup (Vec m a) Integer a # | Index a vector using an |
Lookup (Vec m a) Int a # | Index a vector using an |
(Interface a, KnownNat n) => Lookup (Vec m a) (Bit n) a # | Index a vector using a bit vector |
type Rep (Vec n a) # | |
Defined in Blarney.Vector | |
type SizeOf (Vec n a) # | |
Defined in Blarney.Vector |
Vec
constructors
genVec :: forall n. KnownNat n => Vec n Integer Source #
Generate a Vec
of size n
initialized with integers from '0' to 'n-1'
fromList :: forall n a. KnownNat n => [a] -> Vec n a Source #
Convert a list to a vector, after size check
replicate :: forall n a. KnownNat n => a -> Vec n a Source #
Generate a Vec
with each element initialized to the given value
genWith :: forall n a. KnownNat n => (Integer -> a) -> Vec n a Source #
Generate a Vec
from the given function f
applied to integers from '0'
to 'n-1'
select :: forall i n a. (KnownNat i, (i + 1) <= n) => Vec n a -> a Source #
Select the element from a Vec
at the given type-level index
head :: 1 <= n => Vec n a -> a Source #
Return the head element of the given Vec
(element at index 0)
last :: 1 <= n => Vec n a -> a Source #
Return the last element of the given Vec
(element at last index)
drop :: forall i n a. (KnownNat i, i <= n) => Vec n a -> Vec (n - i) a Source #
Drop the first i
elements of the given Vec
elem :: Cmp a => a -> Vec n a -> Bit 1 Source #
Check that the given value is and element of the given Vec
any :: (a -> Bit 1) -> Vec n a -> Bit 1 Source #
Check that the given predicate holds for any element of the given Vec
all :: (a -> Bit 1) -> Vec n a -> Bit 1 Source #
Check that the given predicate holds for all element of the given Vec
countElem :: (Cmp a, 1 <= n, _) => a -> Vec n a -> Bit (Log2Ceil n + 1) Source #
Return the number of elements of Vec
which are equal to the given value
countIf :: (1 <= n, _) => (a -> Bit 1) -> Vec n a -> Bit (Log2Ceil n + 1) Source #
Return the number of elements of Vec
for which the given predicate holds
zipWith3M :: Monad m => (a -> b -> c -> m d) -> Vec n a -> Vec n b -> Vec n c -> m (Vec n d) Source #
zipWithAny3 :: (a -> b -> c -> d) -> Vec n0 a -> Vec n1 b -> Vec n2 c -> Vec (Min n0 (Min n1 n2)) d Source #