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.lux19
1 files changed, 18 insertions, 1 deletions
diff --git a/stdlib/source/lux/data/sum.lux b/stdlib/source/lux/data/sum.lux
index 2f7624113..5b7dc5a61 100644
--- a/stdlib/source/lux/data/sum.lux
+++ b/stdlib/source/lux/data/sum.lux
@@ -1,6 +1,8 @@
(.module:
{#.doc "Functionality for working with variants (particularly 2-variants)."}
- lux)
+ [lux #*
+ [abstract
+ [equivalence (#+ Equivalence)]]])
(template [<name> <type> <index>]
[(def: #export (<name> value)
@@ -51,3 +53,18 @@
(case x
(0 x') [(#.Cons x' lefts) rights]
(1 x') [lefts (#.Cons x' rights)]))))
+
+(structure: #export (equivalence l@= r@=)
+ (All [l r]
+ (-> (Equivalence l) (Equivalence r)
+ (Equivalence (| l r))))
+ (def: (= reference sample)
+ (case [reference sample]
+ [(#.Left reference) (#.Left sample)]
+ (l@= reference sample)
+
+ [(#.Right reference) (#.Right sample)]
+ (r@= reference sample)
+
+ _
+ false)))