Copyright | (c) ForSyDe Group KTH 2007-2008 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | forsyde-dev@ict.kth.se |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell98 |
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.
Synopsis
- 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, Eq 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
- reduceV :: (a -> a -> a) -> Vector a -> a
- pipeV :: Vector (a -> a) -> a -> 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
- rotateV :: Int -> Vector a -> Vector a
- generateV :: (Num a, Eq a) => a -> (b -> b) -> b -> Vector b
- iterateV :: (Num a, Eq a) => a -> (b -> b) -> b -> Vector b
- copyV :: (Num a, Eq 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, Eq a) => Vector b -> a -> b Source #
The function atV
returns the n-th element in a vector, starting from zero.
replaceV :: Vector a -> Int -> a -> Vector a Source #
The function replaceV
replaces an element in a vector.
tailV :: Vector a -> Vector a Source #
The functions tailV
returns all, but the first element of a vector.
initV :: Vector a -> Vector a Source #
The function initV
returns all but the last elements of a vector.
takeV :: (Num a, Ord a) => a -> Vector b -> Vector b Source #
The function takeV
returns the first n elements of a vector.
dropV :: (Num a, Ord a) => a -> Vector b -> Vector b Source #
The function dropV
drops the first n elements of a vector.
selectV :: Int -> Int -> Int -> Vector a -> Vector a Source #
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.
(<+>) :: Vector a -> Vector a -> Vector a infixr 5 Source #
The operator '(+)' concatinates two vectors.
(<:) :: Vector a -> a -> Vector a infixl 5 Source #
The operator '(<:)' adds an element at the end of a vector.
mapV :: (a -> b) -> Vector a -> Vector b Source #
The higher-order function mapV
applies a function on all elements of a vector.
foldlV :: (a -> b -> a) -> a -> Vector b -> a Source #
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 -> a Source #
The higher-order functions foldrV
folds a function from the left to the right over a vector using an initial value.
reduceV :: (a -> a -> a) -> Vector a -> a Source #
Reduces a vector of elements to a single element based on a binary function.
pipeV :: Vector (a -> a) -> a -> a Source #
Pipes an element through a vector of functions. For example the code
>>>
pipeV [(*2), (+1), (/3)] 3
> 2
is equivalent to
>>>
((*2) . (+1) . (/3)) 3
> 2
zipWithV :: (a -> b -> c) -> Vector a -> Vector b -> Vector c Source #
The higher-order function zipWithV
applies a function pairwise on to vectors.
filterV :: (a -> Bool) -> Vector a -> Vector a Source #
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 a Source #
The function concatV
transforms a vector of vectors to a single vector.
reverseV :: Vector a -> Vector a Source #
The function reverseV
reverses the order of elements in a vector.
shiftlV :: Vector a -> a -> Vector a Source #
The function shiftlV
shifts a value from the left into a vector.
shiftrV :: Vector a -> a -> Vector a Source #
The function shiftrV
shifts a value from the right into a vector.
rotrV :: Vector a -> Vector a Source #
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 a Source #
The function rotlV
rotates a vector to the left. Note that this fuctions does not change the size of a vector.
rotateV :: Int -> Vector a -> Vector a Source #
The function rotateV
rotates a vector based on an index offset.
(> 0)
: rotates the vector left with the corresponding number of positions.(= 0)
: does not modify the vector.(< 0)
: rotates the vector right with the corresponding number of positions.
generateV :: (Num a, Eq a) => a -> (b -> b) -> b -> Vector b Source #
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