Vec-1.0.5: Fixed-length lists and low-dimensional linear algebra.

Safe HaskellNone

Data.Vec.Base

Contents

Synopsis

Documentation

data a :. b Source

The vector constructor. (:.) for vectors is like (:) for lists, and () takes the place of []. (The list of instances here is not meant to be readable.)

Constructors

!a :. !b 

Instances

ZipWith a b c (:. a' u) (:. b' v) (:. c' w) => ZipWith a b c (:. a (:. a' u)) (:. b (:. b' v)) (:. c (:. c' w)) 
ZipWith a b c (:. a (:. a as)) (:. b ()) (:. c ()) 
ZipWith a b c (:. a ()) (:. b (:. b bs)) (:. c ()) 
ZipWith a b c (:. a ()) (:. b ()) (:. c ()) 
Snoc () a (:. a ()) 
Access N0 a (:. a v) 
Vec N1 a (:. a ()) 
Map a b (:. a' u) (:. b' v) => Map a b (:. a (:. a' u)) (:. b (:. b' v)) 
Map a b (:. a ()) (:. b ()) 
(VecArrayRW (:. a v), PackedVec (:. a v)) => IArray UArray (Packed (:. a v)) 
VecArrayRW (:. a v) => IArray UArray (:. a v) 
VecList a (:. a' v) => VecList a (:. a (:. a' v)) 
VecList a (:. a ()) 
(Fractional a, Map (:. a r) r (:. (:. a r) rs) rs_, Map r (:. a r) rs_ (:. (:. a r) rs), Pivot a (:. (:. a r) (:. (:. a r) rs)), GaussElim a rs_) => GaussElim a (:. (:. a r) (:. (:. a r) rs)) 
(Num a, Pivot a (:. (:. a r) ())) => GaussElim a (:. (:. a r) ()) 
Reverse' (:. a p) v v' => Reverse' p (:. a v) v' 
Eq (Packed (Vec4 Bool)) 
Eq (Packed (Vec4 Double)) 
Eq (Packed (Vec4 Float)) 
Eq (Packed (Vec4 Int)) 
Eq (Packed (Vec4 CInt)) 
Eq (Packed (Vec4 CFloat)) 
Eq (Packed (Vec4 CDouble)) 
Eq (Packed (Vec3 Bool)) 
Eq (Packed (Vec3 Double)) 
Eq (Packed (Vec3 Float)) 
Eq (Packed (Vec3 Int)) 
Eq (Packed (Vec3 CInt)) 
Eq (Packed (Vec3 CFloat)) 
Eq (Packed (Vec3 CDouble)) 
Eq (Packed (Vec2 Bool)) 
Eq (Packed (Vec2 Double)) 
Eq (Packed (Vec2 Float)) 
Eq (Packed (Vec2 Int)) 
Eq (Packed (Vec2 CInt)) 
Eq (Packed (Vec2 CFloat)) 
Eq (Packed (Vec2 CDouble)) 
Ord (Packed (Vec4 Bool)) 
Ord (Packed (Vec4 Double)) 
Ord (Packed (Vec4 Float)) 
Ord (Packed (Vec4 Int)) 
Ord (Packed (Vec4 CInt)) 
Ord (Packed (Vec4 CFloat)) 
Ord (Packed (Vec4 CDouble)) 
Ord (Packed (Vec3 Bool)) 
Ord (Packed (Vec3 Double)) 
Ord (Packed (Vec3 Float)) 
Ord (Packed (Vec3 Int)) 
Ord (Packed (Vec3 CInt)) 
Ord (Packed (Vec3 CFloat)) 
Ord (Packed (Vec3 CDouble)) 
Ord (Packed (Vec2 Bool)) 
Ord (Packed (Vec2 Double)) 
Ord (Packed (Vec2 Float)) 
Ord (Packed (Vec2 Int)) 
Ord (Packed (Vec2 CInt)) 
Ord (Packed (Vec2 CFloat)) 
Ord (Packed (Vec2 CDouble)) 
Read (Packed (Vec4 Bool)) 
Read (Packed (Vec4 Double)) 
Read (Packed (Vec4 Float)) 
Read (Packed (Vec4 Int)) 
Read (Packed (Vec4 CInt)) 
Read (Packed (Vec4 CFloat)) 
Read (Packed (Vec4 CDouble)) 
Read (Packed (Vec3 Bool)) 
Read (Packed (Vec3 Double)) 
Read (Packed (Vec3 Float)) 
Read (Packed (Vec3 Int)) 
Read (Packed (Vec3 CInt)) 
Read (Packed (Vec3 CFloat)) 
Read (Packed (Vec3 CDouble)) 
Read (Packed (Vec2 Bool)) 
Read (Packed (Vec2 Double)) 
Read (Packed (Vec2 Float)) 
Read (Packed (Vec2 Int)) 
Read (Packed (Vec2 CInt)) 
Read (Packed (Vec2 CFloat)) 
Read (Packed (Vec2 CDouble)) 
Show (Packed (Vec4 Bool)) 
Show (Packed (Vec4 Double)) 
Show (Packed (Vec4 Float)) 
Show (Packed (Vec4 Int)) 
Show (Packed (Vec4 CInt)) 
Show (Packed (Vec4 CFloat)) 
Show (Packed (Vec4 CDouble)) 
Show (Packed (Vec3 Bool)) 
Show (Packed (Vec3 Double)) 
Show (Packed (Vec3 Float)) 
Show (Packed (Vec3 Int)) 
Show (Packed (Vec3 CInt)) 
Show (Packed (Vec3 CFloat)) 
Show (Packed (Vec3 CDouble)) 
Show (Packed (Vec2 Bool)) 
Show (Packed (Vec2 Double)) 
Show (Packed (Vec2 Float)) 
Show (Packed (Vec2 Int)) 
Show (Packed (Vec2 CInt)) 
Show (Packed (Vec2 CFloat)) 
Show (Packed (Vec2 CDouble)) 
PackedVec (Vec4 Bool) 
PackedVec (Vec4 Double) 
PackedVec (Vec4 Float) 
PackedVec (Vec4 Int) 
PackedVec (Vec4 CInt) 
PackedVec (Vec4 CFloat) 
PackedVec (Vec4 CDouble) 
PackedVec (Vec3 Bool) 
PackedVec (Vec3 Double) 
PackedVec (Vec3 Float) 
PackedVec (Vec3 Int) 
PackedVec (Vec3 CInt) 
PackedVec (Vec3 CFloat) 
PackedVec (Vec3 CDouble) 
PackedVec (Vec2 Bool) 
PackedVec (Vec2 Double) 
PackedVec (Vec2 Float) 
PackedVec (Vec2 Int) 
PackedVec (Vec2 CInt) 
PackedVec (Vec2 CFloat) 
PackedVec (Vec2 CDouble) 
Access n a v => Access (Succ n) a (:. a v) 
Vec (Succ n) a (:. a' v) => Vec (Succ (Succ n)) a (:. a (:. a' v)) 
(VecArrayRW (:. a v), PackedVec (:. a v)) => MArray (STUArray s) (Packed (:. a v)) (ST s) 
Drop n (:. a v) v' => Drop (Succ n) (:. a (:. a v)) v' 
VecArrayRW (:. a v) => MArray (STUArray s) (:. a v) (ST s) 
Take n v v' => Take (Succ n) (:. a v) (:. a v') 
(Eq a, Eq b) => Eq (:. a b) 
(Fractional a, Ord (:. a u), ZipWith a a a (:. a u) (:. a u) (:. a u), Map a a (:. a u) (:. a u), Vec (Succ l) a (:. a u)) => Fractional (:. a u) 
(Num a, Map a a (:. a u) (:. a u), ZipWith a a a (:. a u) (:. a u) (:. a u), Vec (Succ l) a (:. a u)) => Num (:. a u) 
(Ord a, Ord b) => Ord (:. a b) 
(Read a, Read b) => Read (:. a b) 
(Show a, ShowVec v) => Show (:. a v) 
(Vec (Succ (Succ n)) a (:. a (:. a v)), Storable a, Storable (:. a v)) => Storable (:. a (:. a v)) 
Storable a => Storable (:. a ()) 
VecArrayRW (:. Double ()) 
VecArrayRW (:. Double v) => VecArrayRW (:. Double (:. Double v)) 
VecArrayRW (:. Float ()) 
VecArrayRW (:. Float v) => VecArrayRW (:. Float (:. Float v)) 
VecArrayRW (:. Int ()) 
VecArrayRW (:. Int v) => VecArrayRW (:. Int (:. Int v)) 
VecArrayRW (:. Word8 ()) 
VecArrayRW (:. Word8 v) => VecArrayRW (:. Word8 (:. Word8 v)) 
(Show a, ShowVec v) => ShowVec (:. a v) 
(Map (:. a r) r (:. (:. a r) rs) rs_, Map r (:. a r) rs_ (:. (:. a r) rs), Fold aas (a, :. a r), ZipWith a a a (:. a r) (:. a r) (:. a r), Map a a (:. a r) (:. a r), ZipWith a (:. a r) (a, :. a r) r (:. (:. a r) rs) aas, Num a, BackSubstitute' rs_) => BackSubstitute' (:. (:. a r) (:. (:. a r) rs)) 
BackSubstitute' (:. (:. a r) ()) 
(Map (:. a r) r (:. (:. a r) rs) rs_, Map r (:. a r) rs_ (:. (:. a r) rs), Fold aas (a, :. a r), ZipWith a a a (:. a r) (:. a r) (:. a r), Map a a (:. a r) (:. a r), ZipWith a (:. a r) (a, :. a r) r (:. (:. a r) rs) aas, Num a, NearZero a, BackSubstitute rs_) => BackSubstitute (:. (:. a r) (:. (:. a r) rs)) 
NearZero a => BackSubstitute (:. (:. a r) ()) 
Last (:. a' v) a => Last (:. a (:. a' v)) a 
Last (:. a ()) a 
Fold (:. a' u) a => Fold (:. a (:. a' u)) a 
Fold (:. a ()) a 
Tail (:. a as) as 
Head (:. a as) a 
Snoc v a (:. a v) => Snoc (:. a v) a (:. a (:. a v)) 
Append (:. a' v1) v2 v3 => Append (:. a (:. a' v1)) v2 (:. a v3) 
Append (:. a ()) v (:. a v) 
Length v n => Length (:. a v) (Succ n) 
(Vec (Succ n) s (:. s ra), Vec (Succ m) (:. s ra) (:. (:. s ra) a), Vec (Succ m) s (:. s rb), Vec (Succ n) (:. s rb) (:. (:. s rb) b), Transpose' (:. (:. s ra) a) (:. (:. s rb) b)) => Transpose (:. (:. s ra) a) (:. (:. s rb) b) 

class ShowVec v whereSource

Methods

showVec :: v -> StringSource

Instances

ShowVec () 
(Show a, ShowVec v) => ShowVec (:. a v) 

Vector Types

type Vec2 a = a :. (a :. ())Source

type Vec3 a = a :. Vec2 aSource

type Vec4 a = a :. Vec3 aSource

type Vec5 a = a :. Vec4 aSource

type Vec6 a = a :. Vec5 aSource

type Vec7 a = a :. Vec6 aSource

type Vec8 a = a :. Vec7 aSource

type Vec9 a = a :. Vec8 aSource

type Vec10 a = a :. Vec9 aSource

type Vec11 a = a :. Vec10 aSource

type Vec12 a = a :. Vec11 aSource

type Vec13 a = a :. Vec12 aSource

type Vec14 a = a :. Vec13 aSource

type Vec15 a = a :. Vec14 aSource

type Vec16 a = a :. Vec15 aSource

type Vec17 a = a :. Vec16 aSource

type Vec18 a = a :. Vec17 aSource

type Vec19 a = a :. Vec18 aSource

class Vec n a v | n a -> v, v -> n a whereSource

The type constraint Vec n a v infers the vector type v from the length n, a type-level natural, and underlying component type a. So x :: Vec N4 a v => v declares x to be a 4-vector of as.

Methods

mkVec :: n -> a -> vSource

Make a uniform vector of a given length. n is a type-level natural. Use vec when the length can be inferred.

Instances

Vec N1 a (:. a ()) 
Vec (Succ n) a (:. a' v) => Vec (Succ (Succ n)) a (:. a (:. a' v)) 

vec :: Vec n a v => a -> vSource

Make a uniform vector. The length is inferred.

class VecList a v | v -> a whereSource

Build a vector from a list, or access vector elements using run-time indicies, numbered from 0.

Methods

fromList :: [a] -> vSource

Turn a list into a vector of inferred length. The list must be at least as long as the vector, but may be longer. Make a mental note of the distinction between this and matFromList, as you might accidentally use this when you mean that. Because number literals can be converted to vectors, and matrices are vectors of vectors, the following works

 fromList [1,2,3,4] :: Mat22 Int
 > ((1):.(1):.()):.((2):.(2):.()):.()

even though we meant to do this

 matFromList [1,2,3,4] :: Mat22 Int
 > ((1):.(2):.()):.((3):.(4):.()):.()

getElem :: Int -> v -> aSource

Get a vector element, which one determined at runtime.

setElem :: Int -> a -> v -> vSource

Set a vector element, which one determined at runtime

Instances

(VecList a v, PackedVec v) => VecList a (Packed v) 
VecList a (:. a' v) => VecList a (:. a (:. a' v)) 
VecList a (:. a ()) 

class Access n a v | v -> a whereSource

get or set a vector element, known at compile time. Use the Nat types to access vector components. For instance, get n0 gets the x component, set n2 44 sets the z component to 44.

Methods

get :: n -> v -> aSource

set :: n -> a -> v -> vSource

Instances

(Access n a v, PackedVec v) => Access n a (Packed v) 
Access N0 a (:. a v) 
Access n a v => Access (Succ n) a (:. a v) 

List-like functions

class Head v a | v -> a whereSource

The first element.

Methods

head :: v -> aSource

Instances

(Head v h, PackedVec v) => Head (Packed v) h 
Head (:. a as) a 

class Tail v v_ | v -> v_ whereSource

All but the first element.

Methods

tail :: v -> v_Source

Instances

(Tail v t, PackedVec v, PackedVec t) => Tail (Packed v) (Packed t) 
Tail (:. a as) as 

class Map a b u v | u -> a, v -> b, b u -> v, a v -> u whereSource

Apply a function over each element in a vector. Constraint Map a b u v states that u is a vector of as, v is a vector of bs with the same length as u, and the function is of type a -> b.

Methods

map :: (a -> b) -> u -> vSource

Instances

(Map a b u v, PackedVec u, PackedVec v) => Map a b (Packed u) (Packed v) 
Map a b (:. a' u) (:. b' v) => Map a b (:. a (:. a' u)) (:. b (:. b' v)) 
Map a b (:. a ()) (:. b ()) 

class ZipWith a b c u v w | u -> a, v -> b, w -> c, u v c -> w whereSource

Combine two vectors using a binary function. The length of the result is the min of the lengths of the arguments. The constraint ZipWith a b c u v w states that u is a vector of as, v is a vector of bs, w is a vector of cs, and the binary function is of type a -> b -> c.

Methods

zipWith :: (a -> b -> c) -> u -> v -> wSource

Instances

(ZipWith a b c u v w, PackedVec u, PackedVec v, PackedVec w) => ZipWith a b c (Packed u) (Packed v) (Packed w) 
ZipWith a b c (:. a' u) (:. b' v) (:. c' w) => ZipWith a b c (:. a (:. a' u)) (:. b (:. b' v)) (:. c (:. c' w)) 
ZipWith a b c (:. a (:. a as)) (:. b ()) (:. c ()) 
ZipWith a b c (:. a ()) (:. b (:. b bs)) (:. c ()) 
ZipWith a b c (:. a ()) (:. b ()) (:. c ()) 

class Fold v a | v -> a whereSource

Fold a function over a vector.

Methods

fold :: (a -> a -> a) -> v -> aSource

foldl :: (b -> a -> b) -> b -> v -> bSource

foldr :: (a -> b -> b) -> b -> v -> bSource

Instances

(Fold v a, PackedVec v) => Fold (Packed v) a 
Fold (:. a' u) a => Fold (:. a (:. a' u)) a 
Fold (:. a ()) a 

reverse :: Reverse' () v v' => v -> v'Source

Reverse a vector

class Reverse' p v v' | p v -> v' whereSource

Reverse helper function : accumulates the reversed list in its first argument

Methods

reverse' :: p -> v -> v'Source

Instances

Reverse' p () p 
(Reverse' () v v', PackedVec v, PackedVec v') => Reverse' () (Packed v) (Packed v') 
Reverse' (:. a p) v v' => Reverse' p (:. a v) v' 

class Append v1 v2 v3 | v1 v2 -> v3, v1 v3 -> v2 whereSource

Append two vectors

Methods

append :: v1 -> v2 -> v3Source

Instances

Append () v v 
Append (:. a' v1) v2 v3 => Append (:. a (:. a' v1)) v2 (:. a v3) 
Append (:. a ()) v (:. a v) 

class Take n v v' | n v -> v' whereSource

take n v constructs a vector from the first n elements of v. n is a type-level natural. For example take n3 v makes a 3-vector of the first three elements of v.

Methods

take :: n -> v -> v'Source

Instances

Take N0 v () 
(Take (Succ n) v v', PackedVec v, PackedVec v') => Take (Succ n) (Packed v) (Packed v') 
Take n v v' => Take (Succ n) (:. a v) (:. a v') 

class Drop n v v' | n v -> v' whereSource

drop n v strips the first n elements from v. n is a type-level natural. For example drop n2 v drops the first two elements.

Methods

drop :: n -> v -> v'Source

Instances

Drop N0 v v 
(Drop n v v', PackedVec v, PackedVec v') => Drop n (Packed v) (Packed v') 
Drop n (:. a v) v' => Drop (Succ n) (:. a (:. a v)) v' 

class Last v a | v -> a whereSource

Get the last element, usually significant for some reason (quaternions, homogenous coordinates, whatever)

Methods

last :: v -> aSource

Instances

(Last v l, PackedVec v) => Last (Packed v) l 
Last (:. a' v) a => Last (:. a (:. a' v)) a 
Last (:. a ()) a 

class Snoc v a v' | v a -> v', v' -> v a whereSource

snoc v a appends the element a to the end of v.

Methods

snoc :: v -> a -> v'Source

Instances

Snoc () a (:. a ()) 
(Snoc v a v', PackedVec v, PackedVec v') => Snoc (Packed v) a (Packed v') 
Snoc v a (:. a v) => Snoc (:. a v) a (:. a (:. a v)) 

class Length v n | v -> n whereSource

The length of a vector

Methods

length :: v -> IntSource

Instances

Length () N0 
(Length v n, PackedVec v) => Length (Packed v) n 
Length v n => Length (:. a v) (Succ n) 

sum :: (Fold v a, Num a) => v -> aSource

sum of vector elements

product :: (Fold v a, Num a) => v -> aSource

product of vector elements

maximum :: (Fold v a, Ord a) => v -> aSource

maximum vector element

minimum :: (Fold v a, Ord a) => v -> aSource

minimum vector element

toList :: Fold v a => v -> [a]Source

Matrix Types

type Mat22 a = Vec2 (Vec2 a)Source

type Mat23 a = Vec2 (Vec3 a)Source

type Mat24 a = Vec2 (Vec4 a)Source

type Mat32 a = Vec3 (Vec2 a)Source

type Mat33 a = Vec3 (Vec3 a)Source

type Mat34 a = Vec3 (Vec4 a)Source

type Mat35 a = Vec3 (Vec5 a)Source

type Mat36 a = Vec3 (Vec6 a)Source

type Mat42 a = Vec4 (Vec2 a)Source

type Mat43 a = Vec4 (Vec3 a)Source

type Mat44 a = Vec4 (Vec4 a)Source

type Mat45 a = Vec4 (Vec5 a)Source

type Mat46 a = Vec4 (Vec6 a)Source

type Mat47 a = Vec4 (Vec7 a)Source

type Mat48 a = Vec4 (Vec8 a)Source

matToLists :: (Fold v a, Fold m v) => m -> [[a]]Source

convert a matrix to a list-of-lists

matToList :: (Fold v a, Fold m v) => m -> [a]Source

convert a matrix to a list in row-major order

matFromLists :: (Vec j a v, Vec i v m, VecList a v, VecList v m) => [[a]] -> mSource

convert a list-of-lists into a matrix

matFromList :: forall i j v m a. (Vec i v m, Vec j a v, Nat i, VecList a v, VecList v m) => [a] -> mSource

convert a list into a matrix. (row-major order)