forsyde-shallow-3.3.3.0: ForSyDe's Haskell-embedded Domain Specific Language.

Copyright(c) ForSyDe Group KTH 2007-2008
LicenseBSD-style (see the file LICENSE)
Maintainerforsyde-dev@ict.kth.se
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

ForSyDe.Shallow.Core.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) infixr 5 
Instances
Eq a => Eq (Vector a) Source # 
Instance details

Defined in ForSyDe.Shallow.Core.Vector

Methods

(==) :: Vector a -> Vector a -> Bool #

(/=) :: Vector a -> Vector a -> Bool #

Read a => Read (Vector a) Source # 
Instance details

Defined in ForSyDe.Shallow.Core.Vector

Show a => Show (Vector a) Source # 
Instance details

Defined in ForSyDe.Shallow.Core.Vector

Methods

showsPrec :: Int -> Vector a -> ShowS #

show :: Vector a -> String #

showList :: [Vector a] -> ShowS #

vector :: [a] -> Vector a Source #

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 a Source #

The function unitV creates a vector with one element.

nullV :: Vector a -> Bool Source #

The function nullV returns True if a vector is empty.

lengthV :: Vector a -> Int Source #

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

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.

headV :: Vector a -> a Source #

The functions headV returns the first element of a vector.

tailV :: Vector a -> Vector a Source #

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

lastV :: Vector a -> a Source #

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

iterateV :: (Num a, Eq a) => a -> (b -> b) -> b -> Vector b Source #

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, Eq a) => a -> b -> Vector b Source #

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