ForSyDe-3.1.1: ForSyDe's Haskell-embedded Domain Specific Language.

Portabilityportable
Stabilityexperimental
Maintainerforsyde-dev@ict.kth.se

ForSyDe.Shallow.Vector

Description

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

Documentation

data Vector a Source

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.

Constructors

NullV 
a :> (Vector a) 

Instances

Eq a => Eq (Vector a) 
Read a => Read (Vector a) 
Show a => Show (Vector a) 

vector :: [a] -> Vector aSource

The function vector converts a list into a vector.

fromVector :: Vector a -> [a]Source

The function fromVector converts a vector into a list.

unitV :: a -> Vector aSource

The function unitV creates a vector with one element.

nullV :: Vector a -> BoolSource

The function nullV returns True if a vector is empty.

lengthV :: Vector a -> IntSource

The function lengthV returns the number of elements in a value.

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.

headV :: Vector a -> aSource

The functions headV returns the first element of a vector.

tailV :: Vector a -> Vector aSource

The functions tailV returns all, but the first element of a vector.

lastV :: Vector a -> aSource

The function lastV returns the last 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.

(<+>) :: Vector a -> Vector a -> Vector aSource

The operator '(+)' concatinates two vectors.

(<:) :: Vector a -> a -> Vector aSource

The operator '(<:)' adds an element at the end of a vector.

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

iterateV :: Num a => a -> (b -> b) -> b -> Vector bSource

The function iterateV generates a vector with a given number of elements starting from an initial element using a supplied function for the generation of elements.

 Vector> iterateV 5 (+1) 1
 <1,2,3,4,5> :: Vector Integer

copyV :: Num a => a -> b -> Vector bSource

The function copyV generates a vector with a given number of copies of the same element.

 Vector> copyV 7 5 
 <5,5,5,5,5,5,5> :: Vector Integer