aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/sum.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/sum.lux')
-rw-r--r--stdlib/source/lux/data/sum.lux20
1 files changed, 19 insertions, 1 deletions
diff --git a/stdlib/source/lux/data/sum.lux b/stdlib/source/lux/data/sum.lux
index a40aa4619..6a048153c 100644
--- a/stdlib/source/lux/data/sum.lux
+++ b/stdlib/source/lux/data/sum.lux
@@ -2,7 +2,8 @@
{#.doc "Functionality for working with variants (particularly 2-variants)."}
[lux #*
[abstract
- [equivalence (#+ Equivalence)]]])
+ [equivalence (#+ Equivalence)]
+ [hash (#+ Hash)]]])
(template [<name> <type> <right?>]
[(def: #export (<name> value)
@@ -73,3 +74,20 @@
_
false)))
+
+(structure: #export (hash (^open "l@.") (^open "r@."))
+ (All [l r]
+ (-> (Hash l) (Hash r)
+ (Hash (| l r))))
+
+ (def: &equivalence (..equivalence l@= r@=))
+
+ (def: (hash value)
+ (case value
+ (#.Left value)
+ (l@hash value)
+
+ (#.Right value)
+ (.nat ("lux i64 *"
+ (.int 2)
+ (.int (r@hash value)))))))