Module Set

This module is undocumented. This is a list of its definitions.

contains :: Set.T a -> a -> Boolean

Returns True if the set contains the given value.

empty :: Set.T a

The empty set.

fold :: (a -> b -> <c> a) -> a -> Set.T b -> <c> a

Folds over all values of the set starting with the given initial value. The folded function receives the accumulator as its first parameter and the value as its second.

The set has no specified iteration order, so only order-insensitive combinations give a reproducible result.

Example:

> Set.fold (\accum x -> accum + x) 0 (Set.fromList [1, 2, 3])
6
fromList :: [a] -> Set.T a

Creates a set containing the values of the given list. Duplicates in the list collapse into one value, so the result can be smaller than the list.

Example:

> sort (Set.toList (Set.fromList [1, 1, 2]))
[1, 2]

The result is sorted because the order in which toList returns the values is not specified.

isEmpty :: Set.T a -> Boolean

Returns True if the set contains no values.

iter :: (a -> <c> b) -> Set.T a -> <c> ()

Calls the given function with all values of the set.

iterB :: (a -> <b> Boolean) -> Set.T a -> <b> Boolean

Calls the given function with the values of the set until it returns False. Returns False if the iteration was interrupted this way and True if the function accepted all values.

The returned boolean therefore answers "was the iteration allowed to finish", not "did any value match". It is True exactly when the function accepted every value, so iterB reads as "for all" and not as "exists".

Example:

> s = Set.fromList [1, 2, 3]
> Set.iterB (\x -> x < 10) s
True
> Set.iterB (\x -> x < 3) s
False

The second call stops as soon as it reaches the value 3 and reports False even though two of the three values were accepted.

iterI :: (Integer -> a -> <c> b) -> Set.T a -> <c> ()

Calls the given function with all values of the set, giving also a running index as the first parameter. The index starts from zero.

The index is only a counter of how many values have been visited; it is not a position, because the set has no specified iteration order. Iterating a set of three values always produces the indices 0, 1 and 2, but which value gets which index is unspecified.

Example:

> Set.iterI (\i x -> print (show i + ": " + x)) (Set.singleton "only")
0: only
singleton :: a -> Set.T a

A set containing just the given value.

size :: Set.T a -> Integer

The number of values in the set.

toList :: Set.T a -> [a]

The values of the set as a list. The order of the list is not specified; sort it if a reproducible order is needed. See fromList for an example.