Copyright | (C) Frank Staals |
---|---|
License | see the LICENSE file |
Maintainer | Frank Staals |
Safe Haskell | None |
Language | Haskell2010 |
Implementation of \(d\)-dimensional vectors. The implementation automatically selects an optimized representation for small (up to size 4) vectors.
Synopsis
- newtype Vector (d :: Nat) (r :: *) = MKVector {
- _unV :: VectorFamily (Peano d) r
- unV :: Lens (Vector d r) (Vector d s) (VectorFamily (Peano d) r) (VectorFamily (Peano d) s)
- type Arity d = (ImplicitArity (Peano d), KnownNat d)
- readVec :: forall d r. (Arity d, Read r) => ReadP (Vector d r)
- pattern Vector :: VectorFamilyF (Peano d) r -> Vector d r
- pattern Vector1 :: r -> Vector 1 r
- pattern Vector2 :: r -> r -> Vector 2 r
- pattern Vector3 :: r -> r -> r -> Vector 3 r
- pattern Vector4 :: r -> r -> r -> r -> Vector 4 r
- vectorFromList :: Arity d => [r] -> Maybe (Vector d r)
- vectorFromListUnsafe :: Arity d => [r] -> Vector d r
- destruct :: (Arity d, Arity (d + 1)) => Vector (d + 1) r -> (r, Vector d r)
- element :: forall proxy i d r. (Arity d, KnownNat i, (i + 1) <= d) => proxy i -> Lens' (Vector d r) r
- element' :: forall d r. Arity d => Int -> Traversal' (Vector d r) r
- snoc :: (Arity (d + 1), Arity d) => Vector d r -> r -> Vector (d + 1) r
- init :: (Arity d, Arity (d + 1)) => Vector (d + 1) r -> Vector d r
- last :: forall d r. (KnownNat d, Arity (d + 1)) => Vector (d + 1) r -> r
- prefix :: forall i d r. (Arity d, Arity i, i <= d) => Vector d r -> Vector i r
- cross :: Num r => Vector 3 r -> Vector 3 r -> Vector 3 r
d dimensional Vectors
newtype Vector (d :: Nat) (r :: *) Source #
Datatype representing d dimensional vectors. The default implementation is based n VectorFixed. However, for small vectors we automatically select a more efficient representation.
MKVector | |
|
Instances
unV :: Lens (Vector d r) (Vector d s) (VectorFamily (Peano d) r) (VectorFamily (Peano d) s) Source #
Convenience "constructors"
vectorFromListUnsafe :: Arity d => [r] -> Vector d r Source #
Indexing vectors
element :: forall proxy i d r. (Arity d, KnownNat i, (i + 1) <= d) => proxy i -> Lens' (Vector d r) r Source #
Lens into the i th element
element' :: forall d r. Arity d => Int -> Traversal' (Vector d r) r Source #
Similar to element
above. Except that we don't have a static guarantee
that the index is in bounds. Hence, we can only return a Traversal
Snoccing and consindg
snoc :: (Arity (d + 1), Arity d) => Vector d r -> r -> Vector (d + 1) r Source #
Add an element at the back of the vector
init :: (Arity d, Arity (d + 1)) => Vector (d + 1) r -> Vector d r Source #
Get a vector of the first d - 1 elements.
prefix :: forall i d r. (Arity d, Arity i, i <= d) => Vector d r -> Vector i r Source #
Get a prefix of i elements of a vector