diff options
Diffstat (limited to 'stdlib/source/lux/data/sum.lux')
-rw-r--r-- | stdlib/source/lux/data/sum.lux | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/stdlib/source/lux/data/sum.lux b/stdlib/source/lux/data/sum.lux index 5b7dc5a61..a40aa4619 100644 --- a/stdlib/source/lux/data/sum.lux +++ b/stdlib/source/lux/data/sum.lux @@ -4,13 +4,13 @@ [abstract [equivalence (#+ Equivalence)]]]) -(template [<name> <type> <index>] +(template [<name> <type> <right?>] [(def: #export (<name> value) (All [a b] (-> <type> (| a b))) - (<index> value))] + (0 <right?> value))] - [left a 0] - [right b 1]) + [left a #0] + [right b #1]) (def: #export (either fl fr) (All [a b c] @@ -18,8 +18,8 @@ (-> (| a b) c))) (function (_ input) (case input - (0 l) (fl l) - (1 r) (fr r)))) + (0 #0 l) (fl l) + (0 #1 r) (fr r)))) (def: #export (each fl fr) (All [l l' r r'] @@ -27,19 +27,24 @@ (-> (| l r) (| l' r')))) (function (_ input) (case input - (0 l) (0 (fl l)) - (1 r) (1 (fr r))))) + (0 #0 l) (0 #0 (fl l)) + (0 #1 r) (0 #1 (fr r))))) -(template [<name> <side> <tag>] +(template [<name> <side> <right?>] [(def: #export (<name> es) (All [a b] (-> (List (| a b)) (List <side>))) (case es - #.Nil #.Nil - (#.Cons (<tag> x) es') (#.Cons [x (<name> es')]) - (#.Cons _ es') (<name> es')))] + #.Nil + #.Nil + + (#.Cons (0 <right?> x) es') + (#.Cons [x (<name> es')]) + + (#.Cons _ es') + (<name> es')))] - [lefts a 0] - [rights b 1] + [lefts a #0] + [rights b #1] ) (def: #export (partition xs) @@ -51,8 +56,8 @@ (#.Cons x xs') (let [[lefts rights] (partition xs')] (case x - (0 x') [(#.Cons x' lefts) rights] - (1 x') [lefts (#.Cons x' rights)])))) + (0 #0 x') [(#.Cons x' lefts) rights] + (0 #1 x') [lefts (#.Cons x' rights)])))) (structure: #export (equivalence l@= r@=) (All [l r] |