diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/abstract/hash.lux | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/stdlib/source/lux/abstract/hash.lux b/stdlib/source/lux/abstract/hash.lux index 62e72e52a..df2dd2e27 100644 --- a/stdlib/source/lux/abstract/hash.lux +++ b/stdlib/source/lux/abstract/hash.lux @@ -11,14 +11,29 @@ (: (-> a Nat) hash)) +(def: #export (sum left right) + (All [l r] (-> (Hash l) (Hash r) (Hash (| l r)))) + (structure + (def: &equivalence + (equivalence.sum (:: left &equivalence) + (:: right &equivalence))) + (def: (hash value) + (<| (:coerce Nat) + (case value + (#.Left value) + ("lux i64 *" +2 (:coerce Int (:: left hash value))) + + (#.Right value) + ("lux i64 *" +3 (:coerce Int (:: right hash value)))))))) + (def: #export (product left right) - (All [l r] (-> (Hash l) (Hash r) (Hash [l r]))) + (All [l r] (-> (Hash l) (Hash r) (Hash (& l r)))) (structure (def: &equivalence (equivalence.product (:: left &equivalence) (:: right &equivalence))) (def: (hash [leftV rightV]) (:coerce Nat - ("lux i64 *" + ("lux i64 +" (:coerce Int (:: left hash leftV)) (:coerce Int (:: right hash rightV))))))) |