aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/collection/sequence.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/data/collection/sequence.lux')
-rw-r--r--stdlib/source/library/lux/data/collection/sequence.lux112
1 files changed, 56 insertions, 56 deletions
diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux
index bae056369..da7ea73c1 100644
--- a/stdlib/source/library/lux/data/collection/sequence.lux
+++ b/stdlib/source/library/lux/data/collection/sequence.lux
@@ -51,16 +51,16 @@
(type: Index
Nat)
-(def: branching_exponent
+(def branching_exponent
Nat
5)
-(def: root_level
+(def root_level
Level
0)
(with_template [<name> <op>]
- [(def: <name>
+ [(def <name>
(-> Level Level)
(<op> branching_exponent))]
@@ -68,23 +68,23 @@
[level_down n.-]
)
-(def: full_node_size
+(def full_node_size
Nat
(i64.left_shifted branching_exponent 1))
-(def: branch_idx_mask
+(def branch_idx_mask
Nat
(-- full_node_size))
-(def: branch_idx
+(def branch_idx
(-> Index Index)
(i64.and branch_idx_mask))
-(def: (empty_hierarchy _)
+(def (empty_hierarchy _)
(All (_ a) (-> Any (Hierarchy a)))
(array.empty ..full_node_size))
-(def: (tail_off sequence_size)
+(def (tail_off sequence_size)
(-> Nat Nat)
(if (n.< full_node_size sequence_size)
0
@@ -92,7 +92,7 @@
(i64.right_shifted branching_exponent)
(i64.left_shifted branching_exponent))))
-(def: (path level tail)
+(def (path level tail)
(All (_ a) (-> Level (Base a) (Node a)))
(if (n.= 0 level)
{#Base tail}
@@ -100,12 +100,12 @@
(array.has! 0 (path (level_down level) tail))
{#Hierarchy})))
-(def: (tail singleton)
+(def (tail singleton)
(All (_ a) (-> a (Base a)))
(|> (array.empty 1)
(array.has! 0 singleton)))
-(def: (with_tail size level tail parent)
+(def (with_tail size level tail parent)
(All (_ a) (-> Nat Level (Base a) (Hierarchy a) (Hierarchy a)))
(let [sub_idx (branch_idx (i64.right_shifted level (-- size)))
... If we're currently on a bottom node
@@ -126,14 +126,14 @@
(|> (array.clone parent)
(array.has! sub_idx sub_node))))
-(def: (expanded_tail val tail)
+(def (expanded_tail val tail)
(All (_ a) (-> a (Base a) (Base a)))
(let [tail_size (array.size tail)]
(|> (array.empty (++ tail_size))
(array.copy! tail_size 0 tail 0)
(array.has! tail_size val))))
-(def: (hierarchy#has level idx val hierarchy)
+(def (hierarchy#has level idx val hierarchy)
(All (_ a) (-> Level Index a (Hierarchy a) (Hierarchy a)))
(let [sub_idx (branch_idx (i64.right_shifted level idx))]
(case (array.item sub_idx hierarchy)
@@ -151,7 +151,7 @@
_
(undefined))))
-(def: (without_tail size level hierarchy)
+(def (without_tail size level hierarchy)
(All (_ a) (-> Nat Level (Hierarchy a) (Maybe (Hierarchy a))))
(let [sub_idx (branch_idx (i64.right_shifted level (n.- 2 size)))]
(cond (n.= 0 sub_idx)
@@ -176,7 +176,7 @@
{.#Some})
)))
-(def: (node#list node)
+(def (node#list node)
(All (_ a) (-> (Node a) (List a)))
(case node
{#Base base}
@@ -197,18 +197,18 @@
#root (Hierarchy a)
#tail (Base a)]))
-(def: .public empty
+(def .public empty
Sequence
[#level (level_up root_level)
#size 0
#root (empty_hierarchy [])
#tail (array.empty 0)])
-(def: .public (size sequence)
+(def .public (size sequence)
(All (_ a) (-> (Sequence a) Nat))
(the #size sequence))
-(def: .public (suffix val sequence)
+(def .public (suffix val sequence)
(All (_ a) (-> a (Sequence a) (Sequence a)))
... Check if there is room in the tail.
(let [sequence_size (the #size sequence)]
@@ -249,11 +249,11 @@
(exception: base_was_not_found)
-(def: .public (within_bounds? sequence idx)
+(def .public (within_bounds? sequence idx)
(All (_ a) (-> (Sequence a) Nat Bit))
(n.< (the #size sequence) idx))
-(def: (base_for idx sequence)
+(def (base_for idx sequence)
(All (_ a) (-> Index (Sequence a) (Try (Base a))))
(if (within_bounds? sequence idx)
(if (n.< (tail_off (the #size sequence)) idx)
@@ -275,7 +275,7 @@
{try.#Success (the #tail sequence)})
(exception.except ..index_out_of_bounds [sequence idx])))
-(def: .public (item idx sequence)
+(def .public (item idx sequence)
(All (_ a) (-> Nat (Sequence a) (Try a)))
(do try.monad
[base (base_for idx sequence)
@@ -284,7 +284,7 @@
(exception.except ..incorrect_sequence_structure [])
{try.#Success (array.item index base)})))
-(def: .public (has idx val sequence)
+(def .public (has idx val sequence)
(All (_ a) (-> Nat a (Sequence a) (Try (Sequence a))))
(let [sequence_size (the #size sequence)]
(if (within_bounds? sequence idx)
@@ -297,13 +297,13 @@
sequence))}
(exception.except ..index_out_of_bounds [sequence idx]))))
-(def: .public (revised idx revision it)
+(def .public (revised idx revision it)
(All (_ a) (-> Nat (-> a a) (Sequence a) (Try (Sequence a))))
(do try.monad
[val (..item idx it)]
(..has idx (revision val) it)))
-(def: .public (prefix sequence)
+(def .public (prefix sequence)
(All (_ a) (-> (Sequence a) (Sequence a)))
(case (the #size sequence)
0
@@ -348,31 +348,31 @@
(.has #tail new_tail))))))
))
-(def: .public (list sequence)
+(def .public (list sequence)
(All (_ a) (-> (Sequence a) (List a)))
(list#composite (node#list {#Hierarchy (the #root sequence)})
(node#list {#Base (the #tail sequence)})))
-(def: .public of_list
+(def .public of_list
(All (_ a) (-> (List a) (Sequence a)))
(list#mix ..suffix ..empty))
-(def: .public (member? equivalence sequence val)
+(def .public (member? equivalence sequence val)
(All (_ a) (-> (Equivalence a) (Sequence a) a Bit))
(list.member? equivalence (list sequence) val))
-(def: .public empty?
+(def .public empty?
(All (_ a) (-> (Sequence a) Bit))
(|>> (the #size) (n.= 0)))
-(def: .public sequence
+(def .public sequence
(syntax (_ [elems (<>.some <code>.any)])
(in (.list (` (..of_list (.list (~+ elems))))))))
-(def: (node_equivalence //#=)
+(def (node_equivalence //#=)
(All (_ a) (-> (Equivalence a) (Equivalence (Node a))))
(implementation
- (def: (= v1 v2)
+ (def (= v1 v2)
(case [v1 v2]
[{#Base b1} {#Base b2}]
(array.= //#= b1 b2)
@@ -383,10 +383,10 @@
_
#0))))
-(def: .public (equivalence //#=)
+(def .public (equivalence //#=)
(All (_ a) (-> (Equivalence a) (Equivalence (Sequence a))))
(implementation
- (def: (= v1 v2)
+ (def (= v1 v2)
(and (n.= (the #size v1) (the #size v2))
(let [(open "node#[0]") (node_equivalence //#=)]
(and (node#= {#Base (the #tail v1)}
@@ -394,10 +394,10 @@
(node#= {#Hierarchy (the #root v1)}
{#Hierarchy (the #root v2)})))))))
-(def: node_mix
+(def node_mix
(Mix Node)
(implementation
- (def: (mix $ init xs)
+ (def (mix $ init xs)
(case xs
{#Base base}
(array.mix (function (_ _ item output) ($ item output))
@@ -409,10 +409,10 @@
init
hierarchy)))))
-(def: .public mix
+(def .public mix
(Mix Sequence)
(implementation
- (def: (mix $ init xs)
+ (def (mix $ init xs)
(let [(open "[0]") node_mix]
(mix $
(mix $
@@ -420,18 +420,18 @@
{#Hierarchy (the #root xs)})
{#Base (the #tail xs)})))))
-(def: .public monoid
+(def .public monoid
(All (_ a) (Monoid (Sequence a)))
(implementation
- (def: identity ..empty)
+ (def identity ..empty)
- (def: (composite xs ys)
+ (def (composite xs ys)
(list#mix suffix xs (..list ys)))))
-(def: node_functor
+(def node_functor
(Functor Node)
(implementation
- (def: (each $ xs)
+ (def (each $ xs)
(case xs
{#Base base}
{#Base (array.each $ base)}
@@ -439,10 +439,10 @@
{#Hierarchy hierarchy}
{#Hierarchy (array.each (each $) hierarchy)}))))
-(def: .public functor
+(def .public functor
(Functor Sequence)
(implementation
- (def: (each $ xs)
+ (def (each $ xs)
[#level (the #level xs)
#size (the #size xs)
#root (let [ ... TODO: This binding was established to get around a compilation error. Fix and inline!
@@ -450,12 +450,12 @@
(|> xs (the #root) (array.each $)))
#tail (|> xs (the #tail) (array.each $))])))
-(def: .public apply
+(def .public apply
(Apply Sequence)
(implementation
- (def: functor ..functor)
+ (def functor ..functor)
- (def: (on fa ff)
+ (def (on fa ff)
(let [(open "[0]") ..functor
(open "[0]") ..mix
(open "[0]") ..monoid
@@ -463,27 +463,27 @@
ff)]
(mix composite identity results)))))
-(def: .public monad
+(def .public monad
(Monad Sequence)
(implementation
- (def: functor ..functor)
+ (def functor ..functor)
- (def: in
+ (def in
(|>> sequence))
- (def: conjoint
+ (def conjoint
(let [(open "[0]") ..mix
(open "[0]") ..monoid]
(mix (function (_ post pre) (composite pre post)) identity)))))
-(def: .public reversed
+(def .public reversed
(All (_ a) (-> (Sequence a) (Sequence a)))
(|>> ..list
list.reversed
(list#mix suffix ..empty)))
(with_template [<name> <array> <init> <op>]
- [(def: .public <name>
+ [(def .public <name>
(All (_ a)
(-> (Predicate a) (Sequence a) Bit))
(let [help (is (All (_ a)
@@ -504,7 +504,7 @@
[any? array.any? #0 or]
)
-(def: .public (only when items)
+(def .public (only when items)
(All (_ a) (-> (-> a Bit) (Sequence a) (Sequence a)))
(..mix (function (_ item output)
(if (when item)
@@ -513,7 +513,7 @@
..empty
items))
-(def: (one|node check items)
+(def (one|node check items)
(All (_ a b)
(-> (-> a (Maybe b)) (Node a) (Maybe b)))
(case items
@@ -523,7 +523,7 @@
{#Hierarchy items}
(array.one (one|node check) items)))
-(def: .public (one check items)
+(def .public (one check items)
(All (_ a b)
(-> (-> a (Maybe b)) (Sequence a) (Maybe b)))
(case (let [... TODO: This binding was established to get around a compilation error. Fix and inline!