Portability | portable |
---|---|
Stability | experimental |
Maintainer | forsyde-dev@ict.kth.se |
This module defines the data type Vector
and the
corresponding functions. It is a development of the module
defined by Reekie. Though the vector is modeled as a list, it
should be viewed as an array, i.e. a vector has a fixed
size. Unfortunately, it is not possible to have the size of the
vector as a parameter of the vector data type, due to restrictions
in Haskells type system. Still most operations are defined for
vectors with the same size.
- data Vector a
- vector :: [a] -> Vector a
- fromVector :: Vector a -> [a]
- unitV :: a -> Vector a
- nullV :: Vector a -> Bool
- lengthV :: Vector a -> Int
- atV :: Num a => Vector b -> a -> b
- replaceV :: Vector a -> Int -> a -> Vector a
- headV :: Vector a -> a
- tailV :: Vector a -> Vector a
- lastV :: Vector a -> a
- initV :: Vector a -> Vector a
- takeV :: (Num a, Ord a) => a -> Vector b -> Vector b
- dropV :: (Num a, Ord a) => a -> Vector b -> Vector b
- selectV :: Int -> Int -> Int -> Vector a -> Vector a
- groupV :: Int -> Vector a -> Vector (Vector a)
- (<+>) :: Vector a -> Vector a -> Vector a
- (<:) :: Vector a -> a -> Vector a
- mapV :: (a -> b) -> Vector a -> Vector b
- foldlV :: (a -> b -> a) -> a -> Vector b -> a
- foldrV :: (b -> a -> a) -> a -> Vector b -> a
- zipWithV :: (a -> b -> c) -> Vector a -> Vector b -> Vector c
- filterV :: (a -> Bool) -> Vector a -> Vector a
- zipV :: Vector a -> Vector b -> Vector (a, b)
- unzipV :: Vector (a, b) -> (Vector a, Vector b)
- concatV :: Vector (Vector a) -> Vector a
- reverseV :: Vector a -> Vector a
- shiftlV :: Vector a -> a -> Vector a
- shiftrV :: Vector a -> a -> Vector a
- rotrV :: Vector a -> Vector a
- rotlV :: Vector a -> Vector a
- generateV :: Num a => a -> (b -> b) -> b -> Vector b
- iterateV :: Num a => a -> (b -> b) -> b -> Vector b
- copyV :: Num a => a -> b -> Vector b
Documentation
The data type Vector
is modeled similar to a list. It has two data type constructors. NullV
constructs the empty vector, while :>
constructsa vector by adding an value to an existing vector. Using the inheritance mechanism of Haskell we have declared Vector
as an instance of the classes Read
and Show
.
| This means that the vector 1:>2:>3:>NullV is shown as 1,2,3.
fromVector :: Vector a -> [a]Source
The function fromVector
converts a vector into a list.
atV :: Num a => Vector b -> a -> bSource
The function atV
returns the n-th element in a vector, starting from zero.
replaceV :: Vector a -> Int -> a -> Vector aSource
The function replaceV
replaces an element in a vector.
tailV :: Vector a -> Vector aSource
The functions tailV
returns all, but the first element of a vector.
initV :: Vector a -> Vector aSource
The function initV
returns all but the last elements of a vector.
takeV :: (Num a, Ord a) => a -> Vector b -> Vector bSource
The function takeV
returns the first n elements of a vector.
dropV :: (Num a, Ord a) => a -> Vector b -> Vector bSource
The function dropV
drops the first n elements of a vector.
selectV :: Int -> Int -> Int -> Vector a -> Vector aSource
The function selectV
selects elements in the vector. The first argument gives the initial element, starting from zero, the second argument gives the stepsize between elements and the last argument gives the number of elements.
groupV :: Int -> Vector a -> Vector (Vector a)Source
The function groupV
groups a vector into a vector of vectors of size n.
mapV :: (a -> b) -> Vector a -> Vector bSource
The higher-order function mapV
applies a function on all elements of a vector.
foldlV :: (a -> b -> a) -> a -> Vector b -> aSource
The higher-order functions foldlV
folds a function from the right to the left over a vector using an initial value.
foldrV :: (b -> a -> a) -> a -> Vector b -> aSource
The higher-order functions foldrV
folds a function from the left to the right over a vector using an initial value.
zipWithV :: (a -> b -> c) -> Vector a -> Vector b -> Vector cSource
The higher-order function zipWithV
applies a function pairwise on to vectors.
filterV :: (a -> Bool) -> Vector a -> Vector aSource
The higher-function filterV
takes a predicate function and a vector and creates a new vector with the elements for which the predicate is true.
zipV :: Vector a -> Vector b -> Vector (a, b)Source
The function zipV
zips two vectors into a vector of tuples.
unzipV :: Vector (a, b) -> (Vector a, Vector b)Source
The function unzipV
unzips a vector of tuples into two vectors.
concatV :: Vector (Vector a) -> Vector aSource
The function concatV
transforms a vector of vectors to a single vector.
reverseV :: Vector a -> Vector aSource
The function reverseV
reverses the order of elements in a vector.
shiftlV :: Vector a -> a -> Vector aSource
The function shiftlV
shifts a value from the left into a vector.
shiftrV :: Vector a -> a -> Vector aSource
The function shiftrV
shifts a value from the right into a vector.
rotrV :: Vector a -> Vector aSource
The function rotrV
rotates a vector to the right. Note that this fuction does not change the size of a vector.
rotlV :: Vector a -> Vector aSource
The function rotlV
rotates a vector to the left. Note that this fuctions does not change the size of a vector.
generateV :: Num a => a -> (b -> b) -> b -> Vector bSource
The function generateV
behaves in the same way, but starts with the application of the supplied function to the supplied value.
Vector> generateV 5 (+1) 1
<2,3,4,5,6> :: Vector Integer