Skip to content
Open Saka

Sets

A Set describes which Values a Bag may hold. It holds no data itself.

num, str, and bool are the Sets of numbers, strings, and Booleans. Use set to name a Set of your own:

set Product = (
name: str
price: num
active: bool
)

Product is the Set of Records with those three fields.

List the Values that a Set allows:

set Bit = num:{0, 1}

A Set’s name and a colon before braces make a Bag of that Set, as num:{} does:

Bit:{0, 1, 1} // {0, 1'2}
Bit:{2} // error SK4301

An enum makes a new kind of Value with named members:

set enum Priority = {Low, Medium, High}
Priority:Low < Priority:High // {true}

Members sort in the order you declare them. Two enums are different kinds of Values, even when their members have the same names.

A contract pairs a Set with how many occurrences a Bag may hold, its cardinality. After a name, a contract is written after a colon, or with a short marker for a common cardinality:

Contract Short marker Occurrences
x: num'1 x! num Exactly one
x: num'? x? num Zero or one
x: num'+ x+ num One or more
x: num'* x* num Any number
x: num'2..5 — Two to five

The next page uses contracts to declare Flows.