diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/collection/set.lux | 6 | ||||
-rw-r--r-- | stdlib/source/lux/data/collection/set/multi.lux | 38 |
2 files changed, 24 insertions, 20 deletions
diff --git a/stdlib/source/lux/data/collection/set.lux b/stdlib/source/lux/data/collection/set.lux index 4c764b818..f8df4e479 100644 --- a/stdlib/source/lux/data/collection/set.lux +++ b/stdlib/source/lux/data/collection/set.lux @@ -6,6 +6,8 @@ [monoid (#+ Monoid)] ["." hash (#+ Hash)]] [data + [number + ["n" nat]] [collection ["//" dictionary (#+ Dictionary)] ["." list ("#@." fold)]]]]) @@ -59,7 +61,7 @@ (def: &equivalence ..equivalence) (def: (hash (^@ set [hash _])) - (list@fold (function (_ elem acc) (n/+ (:: hash hash elem) acc)) + (list@fold (function (_ elem acc) (n.+ (:: hash hash elem) acc)) 0 (..to-list set)))) @@ -72,7 +74,7 @@ (def: #export empty? (All [a] (-> (Set a) Bit)) - (|>> ..size (n/= 0))) + (|>> ..size (n.= 0))) (def: #export (from-list hash elements) (All [a] (-> (Hash a) (List a) (Set a))) diff --git a/stdlib/source/lux/data/collection/set/multi.lux b/stdlib/source/lux/data/collection/set/multi.lux index c11d4c558..4f3f02276 100644 --- a/stdlib/source/lux/data/collection/set/multi.lux +++ b/stdlib/source/lux/data/collection/set/multi.lux @@ -7,12 +7,14 @@ ["." function] [type (#+ :share) abstract]] - [//// - ["." maybe]] - [/// - ["." list ("#;." fold)] - ["." dictionary (#+ Dictionary)]] - ["." //]) + ["." // + [// + ["." list ("#;." fold)] + ["." dictionary (#+ Dictionary)] + [// + ["." maybe] + [number + ["n" nat]]]]]) (abstract: #export (Set a) {} @@ -25,11 +27,11 @@ (def: #export size (All [a] (-> (Set a) Nat)) - (|>> :representation dictionary.values (list;fold n/+ 0))) + (|>> :representation dictionary.values (list;fold n.+ 0))) (def: #export (add/* count elem set) (All [a] (-> Nat a (Set a) (Set a))) - (|> set :representation (dictionary.update~ elem 0 (n/+ count)) :abstraction)) + (|> set :representation (dictionary.update~ elem 0 (n.+ count)) :abstraction)) (def: #export add/1 (All [a] (-> a (Set a) (Set a))) @@ -43,8 +45,8 @@ {(Set a) set} {(-> (Dictionary a Nat) (Dictionary a Nat)) - (if (n/> count current) - (dictionary.update elem (n/- count)) + (if (n.> count current) + (dictionary.update elem (n.- count)) (dictionary.remove elem))})] (|> set :representation transform :abstraction)) @@ -74,7 +76,7 @@ (def: #export (union parameter subject) (All [a] (-> (Set a) (Set a) (Set a))) - (:abstraction (dictionary.merge-with n/+ (:representation parameter) (:representation subject)))) + (:abstraction (dictionary.merge-with n.+ (:representation parameter) (:representation subject)))) (def: #export (difference parameter subject) (All [a] (-> (Set a) (Set a) (Set a))) @@ -92,7 +94,7 @@ dictionary.entries (list;fold (function (_ [elem count] (^:representation output)) (:abstraction (if (dictionary.contains? elem output) - (dictionary.update elem (n/min count) output) + (dictionary.update elem (n.min count) output) output))) subject))) @@ -106,7 +108,7 @@ :representation (dictionary.get elem) (maybe.default 0) - (n/>= count)))))) + (n.>= count)))))) (def: #export (support set) (All [a] (-> (Set a) (//.Set a))) @@ -117,7 +119,7 @@ (structure: #export equivalence (All [a] (Equivalence (Set a))) (def: (= (^:representation reference) (^:representation sample)) - (and (n/= (dictionary.size reference) + (and (n.= (dictionary.size reference) (dictionary.size sample)) (|> reference dictionary.entries @@ -125,7 +127,7 @@ (|> sample (dictionary.get elem) (maybe.default 0) - (n/= count)))))))) + (n.= count)))))))) (structure: #export hash (All [a] (Hash (Set a))) (def: &equivalence ..equivalence) @@ -133,18 +135,18 @@ (def: (hash (^:representation set)) (let [[Hash<a> _] set] (list;fold (function (_ [elem count] acc) - (|> elem (:: Hash<a> hash) (n/* count) (n/+ acc))) + (|> elem (:: Hash<a> hash) (n.* count) (n.+ acc))) 0 (dictionary.entries set))))) ) (def: #export (member? set elem) (All [a] (-> (Set a) a Bit)) - (|> set (..multiplicity elem) (n/> 0))) + (|> set (..multiplicity elem) (n.> 0))) (def: #export empty? (All [a] (-> (Set a) Bit)) - (|>> ..size (n/= 0))) + (|>> ..size (n.= 0))) (def: #export (from-list Hash<a> subject) (All [a] (-> (Hash a) (List a) (Set a))) |