Module "List.curry"

Library with some useful operations on lists.

Author: Michael Hanus

Version: March 2009


 Exported names:

Functions:
delete | deleteBy | elemIndex | elemIndices | find | findIndex | findIndices | group | groupBy | insertBy | intersect | intersperse | isPrefixOf | isSuffixOf | last | nub | nubBy | partition | replace | sortBy | transpose | union | \\


 Summary of exported functions:

elemIndex  :: a -> [a] -> Maybe Int  deterministic 
          Returns the index i of the first occurrence of an element in a list as (Just i), otherwise Nothing is returned.
elemIndices  :: a -> [a] -> [Int]  deterministic 
          Returns the list of indices of occurrences of an element in a list.
find  :: (a -> Bool) -> [a] -> Maybe a  deterministic 
          Returns the first element e of a list satisfying a predicate as (Just e), otherwise Nothing is returned.
findIndex  :: (a -> Bool) -> [a] -> Maybe Int  deterministic 
          Returns the index i of the first occurrences of a list element satisfying a predicate as (Just i), otherwise Nothing is returned.
findIndices  :: (a -> Bool) -> [a] -> [Int]  deterministic 
          Returns the list of indices of list elements satisfying a predicate.
nub  :: [a] -> [a]  deterministic 
          Removes all duplicates in the argument list.
nubBy  :: (a -> a -> Bool) -> [a] -> [a]  deterministic flexible
          Removes all duplicates in the argument list according to an equivalence relation.
delete  :: a -> [a] -> [a]  deterministic 
          Deletes the first occurrence of an element in a list.
deleteBy  :: (a -> a -> Bool) -> a -> [a] -> [a]  deterministic flexible+rigid
          Deletes the first occurrence of an element in a list according to an equivalence relation.
(\\)  :: [a] -> [a] -> [a]  deterministic 
          Computes the difference of two lists.
union  :: [a] -> [a] -> [a]  deterministic flexible+rigid
          Computes the union of two lists.
intersect  :: [a] -> [a] -> [a]  deterministic flexible+rigid
          Computes the intersection of two lists.
intersperse  :: a -> [a] -> [a]  deterministic flexible
          Puts a separator element between all elements in a list.
transpose  :: [[a]] -> [[a]]  deterministic flexible
          Transposes the rows and columns of the argument.
partition  :: (a -> Bool) -> [a] -> ([a],[a])  deterministic 
          Partitions a list into a pair of lists where the first list contains those elements that satisfy the predicate argument and the second list contains the remaining arguments.
group  :: [a] -> [[a]]  deterministic 
          Splits the list argument into a list of lists of equal adjacent elements.
groupBy  :: (a -> a -> Bool) -> [a] -> [[a]]  deterministic flexible
          Splits the list argument into a list of lists of related adjacent elements.
replace  :: a -> Int -> [a] -> [a]  deterministic flexible+rigid
          Replaces an element in a list.
isPrefixOf  :: [a] -> [a] -> Bool  deterministic flexible
          Checks whether a list is a prefix of another.
isSuffixOf  :: [a] -> [a] -> Bool  deterministic 
          Checks whether a list is a suffix of another.
sortBy  :: (a -> a -> Bool) -> [a] -> [a]  deterministic 
          Sorts a list w.r.t.
insertBy  :: (a -> a -> Bool) -> a -> [a] -> [a]  deterministic flexible+rigid
          Inserts an object into a list according to an ordering relation.
last  :: [a] -> a  deterministic flexible
          Returns the last element of a non-empty list.

 Imported modules:

Maybe
Prelude

 Exported datatypes:


 Exported functions:

elemIndex :: a -> [a] -> Maybe Int  deterministic 

Returns the index i of the first occurrence of an element in a list as (Just i), otherwise Nothing is returned.


elemIndices :: a -> [a] -> [Int]  deterministic 

Returns the list of indices of occurrences of an element in a list.


find :: (a -> Bool) -> [a] -> Maybe a  deterministic 

Returns the first element e of a list satisfying a predicate as (Just e), otherwise Nothing is returned.


findIndex :: (a -> Bool) -> [a] -> Maybe Int  deterministic 

Returns the index i of the first occurrences of a list element satisfying a predicate as (Just i), otherwise Nothing is returned.


findIndices :: (a -> Bool) -> [a] -> [Int]  deterministic 

Returns the list of indices of list elements satisfying a predicate.


nub :: [a] -> [a]  deterministic 

Removes all duplicates in the argument list.


nubBy :: (a -> a -> Bool) -> [a] -> [a]  deterministic flexible

Removes all duplicates in the argument list according to an equivalence relation.


delete :: a -> [a] -> [a]  deterministic 

Deletes the first occurrence of an element in a list.


deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]  deterministic flexible+rigid

Deletes the first occurrence of an element in a list according to an equivalence relation.

Further infos:
  • incompletely defined

(\\) :: [a] -> [a] -> [a]  deterministic 

Computes the difference of two lists.

Example call:  (xs \\ ys)

Parameters:
xs - a list
ys - a list
Returns:
the list where the first occurrence of each element of ys has been removed from xs
Further infos:
  • defined as non-associative infix operator with precedence 5

union :: [a] -> [a] -> [a]  deterministic flexible+rigid

Computes the union of two lists.

Further infos:
  • incompletely defined

intersect :: [a] -> [a] -> [a]  deterministic flexible+rigid

Computes the intersection of two lists.

Further infos:
  • incompletely defined

intersperse :: a -> [a] -> [a]  deterministic flexible

Puts a separator element between all elements in a list.
Example: (intersperse 9 [1,2,3,4]) = [1,9,2,9,3,9,4]

Further infos:
  • solution complete, i.e., able to compute all solutions

transpose :: [[a]] -> [[a]]  deterministic flexible

Transposes the rows and columns of the argument.
Example: (transpose [[1,2,3],[4,5,6]]) = [[1,4],[2,5],[3,6]]


partition :: (a -> Bool) -> [a] -> ([a],[a])  deterministic 

Partitions a list into a pair of lists where the first list contains those elements that satisfy the predicate argument and the second list contains the remaining arguments.
Example: (partition (<4) [8,1,5,2,4,3]) = ([1,2,3],[8,5,4])


group :: [a] -> [[a]]  deterministic 

Splits the list argument into a list of lists of equal adjacent elements.
Example: (group [1,2,2,3,3,3,4]) = [[1],[2,2],[3,3,3],[4]]


groupBy :: (a -> a -> Bool) -> [a] -> [[a]]  deterministic flexible

Splits the list argument into a list of lists of related adjacent elements.

Example call:  (groupBy eq xs)

Parameters:
eq - the relation to classify adjacent elements
xs - the list of elements
Returns:
the list of lists of related adjacent elements

replace :: a -> Int -> [a] -> [a]  deterministic flexible+rigid

Replaces an element in a list.

Example call:  (replace x p ys)

Parameters:
x - the new element
p - the position of the new element (head = 0)
ys - the old list
Returns:
the new list where the p. element is replaced by x
Further infos:
  • incompletely defined

isPrefixOf :: [a] -> [a] -> Bool  deterministic flexible

Checks whether a list is a prefix of another.

Example call:  (isPrefixOf xs ys)

Parameters:
xs - a list
ys - a list
Returns:
True if xs is a prefix of ys

isSuffixOf :: [a] -> [a] -> Bool  deterministic 

Checks whether a list is a suffix of another.

Example call:  (isSuffixOf xs ys)

Parameters:
xs - a list
ys - a list
Returns:
True if xs is a suffix of ys

sortBy :: (a -> a -> Bool) -> [a] -> [a]  deterministic 

Sorts a list w.r.t. an ordering relation by the insertion method.


insertBy :: (a -> a -> Bool) -> a -> [a] -> [a]  deterministic flexible+rigid

Inserts an object into a list according to an ordering relation.

Example call:  (insertBy le x xs)

Parameters:
le - an ordering relation (e.g., less-or-equal)
x - an element
xs - a list
Returns:
a list where the element has been inserted
Further infos:
  • incompletely defined

last :: [a] -> a  deterministic flexible

Returns the last element of a non-empty list.

Further infos:
  • incompletely defined
  • solution complete, i.e., able to compute all solutions


Generated by CurryDoc (Version 0.4.1 of June 7, 2007) at Nov 9 18:02:34 2009