diff options
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/source/lux.lux | 20 | ||||
-rw-r--r-- | stdlib/source/lux/data/product.lux | 10 | ||||
-rw-r--r-- | stdlib/source/lux/data/sum.lux | 24 |
3 files changed, 42 insertions, 12 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 6e08c9cea..7fa2ea692 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -5802,6 +5802,16 @@ (fail "Could not parse anything.") )) +(def: (parse-many tokens) + (-> (List Code) (Meta [(List Code) (List Code)])) + (case tokens + (^ (list& head tail)) + (return [tokens (list)]) + + _ + (fail "Could not parse anything.") + )) + (def: (parse-end tokens) (-> (List Code) (Meta Unit)) (case tokens @@ -5833,8 +5843,8 @@ #let [[[name args] tokens] name+args|tokens] anns|tokens (parse-anns tokens) #let [[anns tokens] anns|tokens] - input-template|tokens (parse-any tokens) - #let [[input-template tokens] input-template|tokens] + input-templates|tokens (parse-many tokens) + #let [[input-templates tokens] input-templates|tokens] _ (parse-end tokens) g!tokens (gensym "tokens") g!compiler (gensym "compiler") @@ -5848,8 +5858,10 @@ (case (~ g!tokens) (^ (list (~+ (list/map (|>> [""] symbol$) args)))) (#.Right [(~ g!compiler) - (list (` (~ (replace-syntax rep-env input-template))))]) - + (list (~+ (list/map (function [template] + (` (` (~ (replace-syntax rep-env template))))) + input-templates)))]) + (~ g!_) (#.Left (~ (text$ (text/compose "Wrong syntax for " name)))) ))))) diff --git a/stdlib/source/lux/data/product.lux b/stdlib/source/lux/data/product.lux index 712e96437..09915b11e 100644 --- a/stdlib/source/lux/data/product.lux +++ b/stdlib/source/lux/data/product.lux @@ -1,4 +1,5 @@ -(.module: {#.doc "Functionality for working with tuples (particularly 2-tuples)."} +(.module: + {#.doc "Functionality for working with tuples (particularly 2-tuples)."} lux) ## [Functions] @@ -36,3 +37,10 @@ (-> [a b] [c d]))) (function [[x y]] [(f x) (g y)])) + +(def: #export (fork f g) + (All [a l r] + (-> (-> a l) (-> a r) + (-> a [l r]))) + (function [x] + [(f x) (g x)])) diff --git a/stdlib/source/lux/data/sum.lux b/stdlib/source/lux/data/sum.lux index c2373c238..1a58127c1 100644 --- a/stdlib/source/lux/data/sum.lux +++ b/stdlib/source/lux/data/sum.lux @@ -1,7 +1,7 @@ -(.module: {#.doc "Functionality for working with variants (particularly 2-variants)."} +(.module: + {#.doc "Functionality for working with variants (particularly 2-variants)."} lux) -## [Values] (do-template [<name> <type> <index>] [(def: #export (<name> value) (All [a b] (-> <type> (| a b))) @@ -10,13 +10,23 @@ [left a +0] [right b +1]) -(def: #export (either f g) - (All [a b c] (-> (-> a c) (-> b c) - (-> (| a b) c))) +(def: #export (either fl fr) + (All [a b c] + (-> (-> a c) (-> b c) + (-> (| a b) c))) (function [input] (case input - (+0 l) (f l) - (+1 r) (g r)))) + (+0 l) (fl l) + (+1 r) (fr r)))) + +(def: #export (each fl fr) + (All [l l' r r'] + (-> (-> l l') (-> r r') + (-> (| l r) (| l' r')))) + (function [input] + (case input + (+0 l) (+0 (fl l)) + (+1 r) (+1 (fr r))))) (do-template [<name> <side> <tag>] [(def: #export (<name> es) |