Go to the Next or Previous section, the Detailed Contents, or the FS(E)L Home Page.


A.1.4 Sets

Syntax

{}, {1,2,3} set literals
{m..n} closed range (from integer m to n inclusive)
{m..} open range (from integer m upwards)
union(a1,a2) set union
inter(a1,a2) set intersection
diff(a1,a2) set difference
Union(A) distributed union
Inter(A) distributed intersection (A must be non-empty)
member(x,a) membership test
card(a) cardinality (count elements)
empty(a) check for empty set
set(s) convert a sequence to a set
Set(a) all subset of a (powerset construction)
Seq(a) set of sequences over a (infinite unless a is empty)
{x1,... xn | x<-a, b} comprehension

Equivalences

union(a1,a2) = { z,z' | z<-a1, z'<-a2 }
inter(a1,a2) = { z | z<-a1, member(z,a2) }
diff(a1,a2) = { z | z<-a1, not member(z,a2) }
Union(A) = { z | z'<-A, z<-z' }
member(x,a) = not empty({ z | z<-a, z==x }
Seq(a) = union({ <> }, { <z>^z' | z<-a z'<-Seq(a) })
{ x | } = { x }
{ x | b, ...} = if b then { x | ...} else {}
{ x | x'<-a, ...} = Union({ { x | ...} | x'<-a })

Remarks

In order to remove duplicates, sets need to compare their elements for equality, so only those types where equality is defined may be placed in sets. In particular, sets of processes are not permitted. See the section on pattern-matching for an example of how to convert a set into a sequence by sorting.

Sets with a leading unary minus (most commonly, sets of negative numbers, `{ -2}') require a space between the opening bracket and minus sign to prevent it being confused with a block comment (see A.7 Mechanics).


Go to the Next or Previous section, the Detailed Contents, or the FS(E)L Home Page.