Type signatures are provisional and may contain errors.
Data jetted sets of nouns. Sets are represented as a law
where the row has no duplicate elements and all elements are stored in ascending order, with the form:
Set Functions
isSet
Copy (isSet x)
> x : a
> Bool
Checks if a value is a valid set.
Copy isSet %[] == 1
isSet %[1 2 3] == 1
isSet (0 1 2 []) == 1
isSet (0 2 2 []) == 0 ; Invalid set representation
isSet [1 2 3] == 0 ; Not a set, just a row
emptySet
Returns an empty set.
Copy emptySet == %[]
emptySet == setFromRow []
emptySet == setDel 1 %[1]
setIsEmpty
Copy (setIsEmpty xs)
> xs : Set a
> Bool
Checks if a set is empty.
Copy setIsEmpty emptySet == 1
setIsEmpty %[1] == 0
setIsEmpty %[1 2 3] == 0
setSing
Copy (setSing e)
> e : a
> Set a
Creates a singleton set containing one element.
Copy setSing 3 == %[3]
setSing {a} == %[a]
setSing 0 == %[0]
setFromRow
Copy (setFromRow xs)
> xs : Row a
> Set a
Creates a set from a row, removing duplicates and sorting.
Copy setFromRow [3 1 2 1] == %[1 2 3]
setFromRow [{a} {b} {a}] == %[a b]
setFromRow [5 4 3 2 1] == %[1 2 3 4 5]
setFromRowAsc
Copy (setFromRowAsc xs)
> xs : Row a
> Set a
Creates a set from a row that is already in ascending order with no duplicates.
Copy setFromRowAsc [1 2 3] == %[1 2 3]
setFromRowAsc [{a} {b} {c}] == %[a b c]
setFromRowAsc [0] == %[0]
setToRow
Copy (setToRow xs)
> xs : Set a
> Row a
Converts a set to a row.
Copy setToRow %[1 2 3] == [1 2 3]
setToRow %[a b c] == [a b c]
setToRow %[] == []
setLen
Copy (setLen xs)
> xs : Set a
> Nat
Returns the number of elements in a set.
Copy setLen %[] == 0
setLen %[1 2 3] == 3
setLen %[a] == 1
setToList
Copy (setToList xs)
> xs : Set a
> List a
Converts a set to a list.
Copy setToList %[1 2 3] == [1 [2 [3 0]]]
setToList %[a b] == [%a [%b 0]]
setToList %[] == 0 ; NIL
setFoldl
Copy (setFoldl f z xs)
> f : (b > a > b)
> z : b
> xs : Set a
> b
Left-associative fold over a set.
Copy setFoldl add 0 %[1 2 3] == 6
setFoldl mul 1 %[1 2 3 4] == 24
setFoldl (flip CONS) NIL %[1 2 3] == [3 [2 [1 0]]]
setFoldr
Copy (setFoldr f z xs)
> f : (a > b > b)
> z : b
> xs : Set a
> b
Right-associative fold over a set.
Copy setFoldr (flip CONS) NIL %[1 2 3] == [[[0 3] 2] 1]
setFoldr sub 0 %[1 2 3] == 1
setFoldr strWeld {} %[{a} {b} {c}] == %abc
setIns
Copy (setIns e xs)
> e : a
> xs : Set a
> Set a
Inserts an element into a set.
Copy setIns 3 %[1 2] == %[1 2 3]
setIns 2 %[1 2] == %[1 2] ; No change if element already exists
setIns {a} %[b c] == %[a b c]
setDel
Copy (setDel e xs)
> e : a
> xs : Set a
> Set a
Removes an element from a set.
Copy setDel 2 %[1 2 3] == %[1 3]
setDel 4 %[1 2 3] == %[1 2 3] ; No change if element doesn't exist
setDel {b} %[a b c] == %[a c]
setHas
Copy (setHas e xs)
> e : a
> xs : Set a
> Bool
Checks if an element is in a set.
Copy setHas 2 %[1 2 3] == 1
setHas 4 %[1 2 3] == 0
setHas {b} %[a b c] == 1
setWeld
Copy (setWeld xs ys)
> xs : Set a
> ys : Set a
> Set a
Combines two sets.
Copy setWeld %[1 2] %[2 3] == %[1 2 3]
setWeld %[a b] %[c d] == %[a b c d]
setWeld %[] %[1 2 3] == %[1 2 3]
setUnion
Copy (setUnion xs ys)
> xs : Set a
> ys : Set a
> Set a
Alias for setWeld. Combines two sets.
Copy setUnion %[1 2] %[2 3] == %[1 2 3]
setUnion %[a b] %[c d] == %[a b c d]
setUnion %[] %[1 2 3] == %[1 2 3]
setCatRow
Copy (setCatRow xs)
> xs : Row (Set a)
> Set a
Combines a row of sets into a single set.
Copy setCatRow [%[1 2] %[2 3] %[3 4]] == %[1 2 3 4]
setCatRow [%[a b] %[c] %[d e]] == %[a b c d e]
setCatRow [%[] %[1] %[]] == %[1]
setCatList
Copy (setCatList xs)
> xs : List (Set a)
> Set a
Combines a list of sets into a single set.
Copy setCatList [%[1 2] [%[3 4] [%[2 3] 0]]] == %[1 2 3 4]
setCatList [%[a b] [%[c] [%[d e] 0]]] == %[a b c d e]
setCatList [%[] [%[1] [%[] 0]]] == %[1]
setCatRowAsc
Copy (setCatRowAsc x)
> xs : Row (Set a)
> Set a
Combines a row of sets that are already in ascending order.
Copy setCatRowAsc [%[1 2] %[3 4] %[5 6]] == %[1 2 3 4 5 6]
setCatRowAsc [%[a b] %[c d] %[e f]] == %[a b c d e f]
setCatRowAsc [%[] %[1] %[2 3]] == %[1 2 3]
setMin
Copy (setMin xs)
> xs : Set a
> a
Returns the minimum element in a set.
Copy setMin %[1 2 3] == 1
setMin %[c b a] == a
setMin %[5] == 5
setMax
Copy (setMax xs)
> xs : Set a
> a
Returns the maximum element in a set.
Copy setMax %[1 2 3] == 3
setMax %[c b a] == c
setMax %[5] == 5
setPop
Copy (setPop xs)
> xs : Set a
> (a, Set a)
Removes and returns the minimum element from a set.
Copy setPop %[1 2 3 4] == [1 %[2 3 4]]
setPop %[a b c] == [%a %[b c]]
setPop %[5] == [5 %[]]
setDrop
Copy (setDrop n xs)
> n : Nat
> xs : Set a
> Set a
Removes the first n elements from a set.
Copy setDrop 2 %[1 2 3 4] == %[3 4]
setDrop 1 %[a b c] == %[b c]
setDrop 0 %[1 2 3] == %[1 2 3]
setTake
Copy (setTake n xs)
> n : Nat
> xs : Set a
> Set a
Keeps the first n elements of a set.
Copy setTake 2 %[1 2 3 4] == %[1 2]
setTake 3 %[a b c d] == %[a b c]
setTake 0 %[1 2 3] == %[]
setSplitAt
Copy (setSplitAt i xs)
> i : Nat
> xs : Set a
> (Set a, Set a)
Splits a set at a given index.
Copy setSplitAt 2 %[1 2 3 4] == [%[1 2] %[3 4]]
setSplitAt 1 %[a b c] == [%[a] %[b c]]
setSplitAt 0 %[1 2 3] == [%[] %[1 2 3]]
setSplitLT
Copy (setSplitLT n xs)
> n : a
> xs : Set a
> (Set a, Set a)
Splits a set into elements less than a given value and the rest.
Copy setSplitLT 3 %[1 2 3 4 5] == [%[1 2] %[3 4 5]]
setSplitLT {c} %[a b c d e] == [%[a b] %[c d e]]
setSplitLT 0 %[1 2 3] == [%[] %[1 2 3]]
setIntersect
Copy (setIntersect xs ys)
> xs : Set a
> ys : Set a
> Set a
Returns the intersection of two sets.
Copy setIntersect %[1 2 3] %[2 3 4] == %[2 3]
setIntersect %[a b c] %[b c d] == %[b c]
setIntersect %[1 2 3] %[4 5 6] == %[]
setSub
Copy (setSub xs ys)
> xs : Set a
> ys : Set a
> Set a
Subtracts one set from another.
Copy setSub %[1 2 3] %[2 3] == %[1]
setSub %[a b c d] %[b d] == %[a c]
setSub %[1 2 3] %[4 5 6] == %[1 2 3]
setElem
Copy (setElem n xs)
> n : Nat
> xs : Set a
> a
Returns the nth element of a set.
Copy setElem 1 %[1 2 3] == 2
setElem 0 %[a b c] == %a
setElem 2 %[x y z] == %z
setDifference
Alias for setSub.
setInsert
Alias for setIns.
setSubtract
Alias for setSub.
setIntersection
Alias for setIntersect.