Version: 0.25.0


Sets are unordered collections of unique values of the same type.

let empty: set<'value>

Create an empty set.

let my_set: set<int> = Set.empty;
let literal: (input: list<'value>) => set<'value>

Create a non-empty set.

let my_set : set<int> =
Set.literal(list([3, 2, 2, 1]));
let mem: (v: 'value, set: set<'value>) => bool

Checks if a value exists in the set.

let contains_3 : bool = Set.mem (3, my_set);
let cardinal: (set: set<'value>) => nat

Number of elements in a set.

let cardinal: nat = Set.size(my_set);
let add: (value: 'value, set: set<'value>) => set<'value>

Add a value to a set.

let updated_set = Set.add (4, my_set);
let remove: (value: 'value, set: set<'value>) => set<'value>

Remove a value from a set.

let updated_set = Set.remove (3, my_set);
let update: (value : 'a, flag : bool, set : set<'a>) => set<'a>

add or remove an element in a set based on the boolean value being passed.

// in case of true value will be added to the set
let updated_set = Set.update (4, true, my_set);
// in case of false value will be removed from the set
let updated_set = Set.update (4, false, my_set);
let iter: (iterator: ((item: 'a) => unit), set: set<'a>) => unit

Iterate over values in a set.

let iter_op = (s: set<int>): unit => {
let predicate = (i : int): unit => assert(i > 3);
Set.iter(predicate, s);
let fold: ((iterator: [accumulator: 'accumulator, item: 'item]) => 'accumulator), set: set<'item>, accumulator: 'accumulator) => 'accumulator

Fold over values in a set

let sum = ([acc, i]: [int, int]): int => acc + i;
let sum_of_elements: int = Set.fold(sum, my_set, 0);
let fold_desc: (((a: ['item, 'accumulator]) => 'accumulator), set<'item>, 'accumulator) => 'accumulator

Fold over values in a set

let sum_right = ([i, acc] : [int, int]) : int => acc + i;
let sum_of_elements : int = Set.fold_desc (sum_right, my_set, 0);