From ac68b9bdf7fb8195e8c3862285efa19e59505c2a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 1 Dec 2016 15:52:51 -0400 Subject: - Improved the implementation of vector equality. --- stdlib/source/lux/data/struct/vector.lux | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/data/struct/vector.lux b/stdlib/source/lux/data/struct/vector.lux index bb31063a4..4b8fb4bf3 100644 --- a/stdlib/source/lux/data/struct/vector.lux +++ b/stdlib/source/lux/data/struct/vector.lux @@ -352,9 +352,25 @@ (wrap (list (` (from-list (list (~@ elems))))))) ## [Structures] +(struct: #export (Eq Eq) (All [a] (-> (Eq a) (Eq (Node a)))) + (def: (= v1 v2) + (case [v1 v2] + [(#Base b1) (#Base b2)] + (:: (array;Eq Eq) = b1 b2) + + [(#Hierarchy h1) (#Hierarchy h2)] + (:: (array;Eq (Eq Eq)) = h1 h2) + ))) + (struct: #export (Eq Eq) (All [a] (-> (Eq a) (Eq (Vector a)))) (def: (= v1 v2) - (:: (list;Eq Eq) = (to-list v1) (to-list v2)))) + (and (=+ (get@ #size v1) (get@ #size v2)) + (:: (Eq Eq) = + (#Base (get@ #tail v1)) + (#Base (get@ #tail v2))) + (:: (Eq Eq) = + (#Hierarchy (get@ #root v1)) + (#Hierarchy (get@ #root v2)))))) (struct: _ (Fold Node) (def: (fold f init xs) -- cgit v1.2.3