From f97fa764ed08a758753111c4e92fce1bbb314afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20V=C3=A9rit=C3=A9?= Date: Sat, 7 Dec 2024 19:20:44 +0100 Subject: [PATCH] Implement builtin type Map, and its corresponding functions, as well as the Maybe type --- examples/example_fun.bend | 1 - examples/parallel_and.bend | 4 -- src/fun/builtins.bend | 5 ++ tests/builtin_Map_tests.bend | 4 -- .../mismatched_ask_statements.bend | 10 ++-- .../compile_file_o_all/list_merge_sort.bend | 1 - .../match_adt_non_exhaustive.bend | 4 +- .../non_exhaustive_and.bend | 6 +-- .../golden_tests/desugar_file/ask_branch.bend | 10 ++-- .../encode_pattern_match/and3.bend | 7 ++- .../encode_pattern_match/bool_tup.bend | 8 ++- .../encode_pattern_match/common.bend | 2 - .../definition_merge.bend | 1 - .../encode_pattern_match/list_merge_sort.bend | 1 - .../match_adt_unscoped_lambda.bend | 4 +- .../match_adt_unscoped_var.bend | 2 - .../encode_pattern_match/var_only.bend | 2 - .../mutual_recursion/odd_even.bend | 2 - .../golden_tests/parse_file/imp_program.bend | 4 -- tests/golden_tests/run_file/example.bend | 1 - .../golden_tests/run_file/filter_bool_id.bend | 10 ++-- tests/golden_tests/run_file/mixed_syntax.bend | 4 -- tests/golden_tests/run_file/unbound_wrap.bend | 2 - .../run_file/unscoped_never_used.bend | 6 +-- .../simplify_matches/double_unwrap_maybe.bend | 4 +- ...e_file_o_all__non_exhaustive_and.bend.snap | 2 +- .../desugar_file__ask_branch.bend.snap | 20 +++---- .../desugar_file__mapper_syntax.bend.snap | 54 ++++++++++++------- .../encode_pattern_match__and3.bend.snap | 32 +++++------ .../encode_pattern_match__bool_tup.bend.snap | 32 +++++------ .../encode_pattern_match__common.bend.snap | 18 ------- ..._pattern_match__definition_merge.bend.snap | 18 ------- .../encode_pattern_match__full_map.bend.snap | 14 +++-- ...e_pattern_match__list_merge_sort.bend.snap | 18 ------- ...match__match_adt_unscoped_lambda.bend.snap | 29 ++-------- ...rn_match__match_adt_unscoped_var.bend.snap | 25 +++------ .../encode_pattern_match__var_only.bend.snap | 18 ------- tests/snapshots/parse_file__imp_map.bend.snap | 21 ++++++-- .../parse_file__imp_program.bend.snap | 39 ++++++++------ .../run_file__filter_bool_id.bend.snap | 4 +- .../run_file__nested_map_get.bend.snap | 4 +- .../run_file__nested_map_set.bend.snap | 4 +- .../run_file__unbound_wrap.bend.snap | 4 +- ...ify_matches__double_unwrap_maybe.bend.snap | 4 +- 44 files changed, 177 insertions(+), 288 deletions(-) diff --git a/examples/example_fun.bend b/examples/example_fun.bend index 8d701be0c..4e1b73568 100644 --- a/examples/example_fun.bend +++ b/examples/example_fun.bend @@ -44,7 +44,6 @@ bad_nums : Any = (+ id 1) # Write new data types like this type Option = (Some val) | None -type Bool = True | False # You can have pattern matching on definitions # Use `*` to ignore a pattern diff --git a/examples/parallel_and.bend b/examples/parallel_and.bend index bd41552da..2dcd9cdd6 100644 --- a/examples/parallel_and.bend +++ b/examples/parallel_and.bend @@ -1,8 +1,4 @@ # This program allocates a tree with True at the leaves then parallel ANDs them. -type Bool: - True - False - def and(a: Bool, b: Bool) -> Bool: match a: case Bool/True: diff --git a/src/fun/builtins.bend b/src/fun/builtins.bend index 47d379517..e1136fc66 100644 --- a/src/fun/builtins.bend +++ b/src/fun/builtins.bend @@ -170,6 +170,11 @@ def Tree/reverse(tree: Tree(T)) -> Tree(T): case Tree/Node: return ![tree.right, tree.left] +# BOOL Impl +type Bool: + True + False + # MAYBE Impl diff --git a/tests/builtin_Map_tests.bend b/tests/builtin_Map_tests.bend index b13bc3131..5b21331bd 100644 --- a/tests/builtin_Map_tests.bend +++ b/tests/builtin_Map_tests.bend @@ -1,7 +1,3 @@ -type Bool: - True - False - # Returns values from a map def test1() -> (u24, u24): m = {1: 1, 2: 2, 3: 3} diff --git a/tests/golden_tests/compile_file/mismatched_ask_statements.bend b/tests/golden_tests/compile_file/mismatched_ask_statements.bend index ba41a78ff..86b2504c1 100644 --- a/tests/golden_tests/compile_file/mismatched_ask_statements.bend +++ b/tests/golden_tests/compile_file/mismatched_ask_statements.bend @@ -1,12 +1,8 @@ -type Bool: - T - F - def main: with IO: - match _ = Bool/T: - case Bool/T: + match _ = Bool/True: + case Bool/False: x <- wrap(0) - case Bool/F: + case Bool/False: x = wrap(0) return wrap(x) diff --git a/tests/golden_tests/compile_file_o_all/list_merge_sort.bend b/tests/golden_tests/compile_file_o_all/list_merge_sort.bend index a11946b93..9528ff9b8 100644 --- a/tests/golden_tests/compile_file_o_all/list_merge_sort.bend +++ b/tests/golden_tests/compile_file_o_all/list_merge_sort.bend @@ -1,4 +1,3 @@ -type Bool = True | False type List_ = (Cons head tail) | Nil If Bool/True then else = then diff --git a/tests/golden_tests/compile_file_o_all/match_adt_non_exhaustive.bend b/tests/golden_tests/compile_file_o_all/match_adt_non_exhaustive.bend index 8a97cad1d..ca42b06f7 100644 --- a/tests/golden_tests/compile_file_o_all/match_adt_non_exhaustive.bend +++ b/tests/golden_tests/compile_file_o_all/match_adt_non_exhaustive.bend @@ -1,9 +1,7 @@ -type Maybe = (Some val) | None - main = @maybe match maybe { Maybe/None: 0 - Maybe/Some: match maybe.val { + Maybe/Some: match maybe.value { Maybe/None: 0 } } diff --git a/tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend b/tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend index fe6b4fe92..c897858ec 100644 --- a/tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend +++ b/tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend @@ -1,6 +1,4 @@ -type Bool = T | F - -Bool.and Bool/T Bool/T = Bool/T -Bool.and Bool/F Bool/F = Bool/F +Bool.and Bool/True Bool/True = Bool/True +Bool.and Bool/False Bool/False = Bool/False Main = * diff --git a/tests/golden_tests/desugar_file/ask_branch.bend b/tests/golden_tests/desugar_file/ask_branch.bend index ce8fcbe89..98f5871c6 100644 --- a/tests/golden_tests/desugar_file/ask_branch.bend +++ b/tests/golden_tests/desugar_file/ask_branch.bend @@ -1,12 +1,8 @@ -type Bool: - T - F - def main: with IO: - match _ = Bool/T: - case Bool/T: + match _ = Bool/True: + case Bool/True: x <- wrap(0) - case Bool/F: + case Bool/False: x <- wrap(0) return wrap(x) diff --git a/tests/golden_tests/encode_pattern_match/and3.bend b/tests/golden_tests/encode_pattern_match/and3.bend index 670e709eb..b6f465f08 100644 --- a/tests/golden_tests/encode_pattern_match/and3.bend +++ b/tests/golden_tests/encode_pattern_match/and3.bend @@ -1,6 +1,5 @@ -type Bool = T | F -And (Bool/T, Bool/T, Bool/T) = Bool/T -And * = Bool/F +And (Bool/True, Bool/True, Bool/True) = Bool/True +And * = Bool/False -main = (And (Bool/F, Bool/T, Bool/F)) +main = (And (Bool/False, Bool/True, Bool/False)) diff --git a/tests/golden_tests/encode_pattern_match/bool_tup.bend b/tests/golden_tests/encode_pattern_match/bool_tup.bend index efc7af9c8..9136cfb76 100644 --- a/tests/golden_tests/encode_pattern_match/bool_tup.bend +++ b/tests/golden_tests/encode_pattern_match/bool_tup.bend @@ -1,6 +1,4 @@ -type Bool = T | F +foo (Bool/True, x) = x +foo * = Bool/False -foo (Bool/T, x) = x -foo * = Bool/F - -main = (foo (Bool/F, Bool/T)) +main = (foo (Bool/False, Bool/True)) diff --git a/tests/golden_tests/encode_pattern_match/common.bend b/tests/golden_tests/encode_pattern_match/common.bend index 4667e42cf..082497187 100644 --- a/tests/golden_tests/encode_pattern_match/common.bend +++ b/tests/golden_tests/encode_pattern_match/common.bend @@ -14,8 +14,6 @@ type List_ = (Cons x xs) | Nil -type Bool = True | False - type Light = Red | Yellow | Green type Direction diff --git a/tests/golden_tests/encode_pattern_match/definition_merge.bend b/tests/golden_tests/encode_pattern_match/definition_merge.bend index 052cfe252..c63c0aaca 100644 --- a/tests/golden_tests/encode_pattern_match/definition_merge.bend +++ b/tests/golden_tests/encode_pattern_match/definition_merge.bend @@ -1,5 +1,4 @@ type Either = (Left value) | (Right value) -type Bool = True | False Foo (Either/Left Bool/False) (Either/Left Bool/False) = 1 Foo (Either/Left Bool/False) (Either/Left Bool/True) = 1 diff --git a/tests/golden_tests/encode_pattern_match/list_merge_sort.bend b/tests/golden_tests/encode_pattern_match/list_merge_sort.bend index 6507e6616..dcf3d3899 100644 --- a/tests/golden_tests/encode_pattern_match/list_merge_sort.bend +++ b/tests/golden_tests/encode_pattern_match/list_merge_sort.bend @@ -1,4 +1,3 @@ -type Bool = True | False type List_ = (Cons head tail) | Nil If Bool/True then else = then diff --git a/tests/golden_tests/encode_pattern_match/match_adt_unscoped_lambda.bend b/tests/golden_tests/encode_pattern_match/match_adt_unscoped_lambda.bend index ff300d92b..668bdb993 100644 --- a/tests/golden_tests/encode_pattern_match/match_adt_unscoped_lambda.bend +++ b/tests/golden_tests/encode_pattern_match/match_adt_unscoped_lambda.bend @@ -1,6 +1,4 @@ -type Maybe = None | (Some val) - main = (match x = (Maybe/Some 1) { Maybe/None: @$x * - Maybe/Some: x.val + Maybe/Some: x.value } $x) diff --git a/tests/golden_tests/encode_pattern_match/match_adt_unscoped_var.bend b/tests/golden_tests/encode_pattern_match/match_adt_unscoped_var.bend index 08a199066..6de945c97 100644 --- a/tests/golden_tests/encode_pattern_match/match_adt_unscoped_var.bend +++ b/tests/golden_tests/encode_pattern_match/match_adt_unscoped_var.bend @@ -1,5 +1,3 @@ -type Maybe = None | (Some val) - Foo = @$x match x = (Maybe/Some 1) { Maybe/None: $x Maybe/Some: x.val diff --git a/tests/golden_tests/encode_pattern_match/var_only.bend b/tests/golden_tests/encode_pattern_match/var_only.bend index 5876a4d15..b1d742a9a 100644 --- a/tests/golden_tests/encode_pattern_match/var_only.bend +++ b/tests/golden_tests/encode_pattern_match/var_only.bend @@ -1,5 +1,3 @@ -type Bool = False | True - (Foo a b) = λf (f a) (Foo a b) = b diff --git a/tests/golden_tests/mutual_recursion/odd_even.bend b/tests/golden_tests/mutual_recursion/odd_even.bend index 612e01f55..600b085a5 100644 --- a/tests/golden_tests/mutual_recursion/odd_even.bend +++ b/tests/golden_tests/mutual_recursion/odd_even.bend @@ -1,5 +1,3 @@ -type Bool = True | False - (if_ 0 then else) = else (if_ _ then else) = then diff --git a/tests/golden_tests/parse_file/imp_program.bend b/tests/golden_tests/parse_file/imp_program.bend index 7c3ea9e14..f9bf6727a 100644 --- a/tests/golden_tests/parse_file/imp_program.bend +++ b/tests/golden_tests/parse_file/imp_program.bend @@ -1,10 +1,6 @@ type Point: Point { x, y } -type Bool: - True - False - def symbols(): x = { `x`: 5, 2: 3 }; diff --git a/tests/golden_tests/run_file/example.bend b/tests/golden_tests/run_file/example.bend index fe374cd63..92a1124a3 100644 --- a/tests/golden_tests/run_file/example.bend +++ b/tests/golden_tests/run_file/example.bend @@ -27,7 +27,6 @@ # Write new data types like this type Option = (Some val) | None -type Bool = True | False # You can have pattern matching on definitions # Use `*` to ignore a pattern diff --git a/tests/golden_tests/run_file/filter_bool_id.bend b/tests/golden_tests/run_file/filter_bool_id.bend index f8d49cd40..ba2e6b3c7 100644 --- a/tests/golden_tests/run_file/filter_bool_id.bend +++ b/tests/golden_tests/run_file/filter_bool_id.bend @@ -1,17 +1,13 @@ -type Bool: - T - F - def filter(f, ls): match ls: case List/Nil: return List/Nil case List/Cons: match f(ls.head): - case Bool/T: + case Bool/True: return List/Cons(ls.head, filter(f, ls.tail)) - case Bool/F: + case Bool/False: return filter(f, ls.tail) def main: - return filter(lambda x: x, [Bool/T]) + return filter(lambda x: x, [Bool/True]) diff --git a/tests/golden_tests/run_file/mixed_syntax.bend b/tests/golden_tests/run_file/mixed_syntax.bend index 766d3bed9..6b47e8b56 100644 --- a/tests/golden_tests/run_file/mixed_syntax.bend +++ b/tests/golden_tests/run_file/mixed_syntax.bend @@ -1,7 +1,3 @@ -type Bool: - True - False - type MyTree = (node ~lft ~rgt) | (leaf val) def tree_xor(tree): diff --git a/tests/golden_tests/run_file/unbound_wrap.bend b/tests/golden_tests/run_file/unbound_wrap.bend index b21d4a799..154344ea5 100644 --- a/tests/golden_tests/run_file/unbound_wrap.bend +++ b/tests/golden_tests/run_file/unbound_wrap.bend @@ -1,5 +1,3 @@ -type Maybe = (Some x) | None - Maybe/bind val nxt = match val { Maybe/Some: (nxt val.x) Maybe/None: Maybe/None diff --git a/tests/golden_tests/run_file/unscoped_never_used.bend b/tests/golden_tests/run_file/unscoped_never_used.bend index 07edaa7a2..685863e55 100644 --- a/tests/golden_tests/run_file/unscoped_never_used.bend +++ b/tests/golden_tests/run_file/unscoped_never_used.bend @@ -1,6 +1,4 @@ -type Bool = T | F - main = @x match x { - Bool/T : @$x * - Bool/F : @x * + Bool/True : @$x * + Bool/False : @x * } diff --git a/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend b/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend index bea8cfe57..a126be96d 100644 --- a/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend +++ b/tests/golden_tests/simplify_matches/double_unwrap_maybe.bend @@ -1,7 +1,5 @@ # We want to make sure that the default value is not mistakenly erased in the first level of flattening. -type Maybe = (Some x) | None - -(DoubleUnwrap (Maybe/Some (Maybe/Some x)) *) = x +(DoubleUnwrap (Maybe/Some (Maybe/Some val)) *) = val (DoubleUnwrap * x) = x Main = (DoubleUnwrap (Maybe/Some Maybe/None) 5) diff --git a/tests/snapshots/compile_file_o_all__non_exhaustive_and.bend.snap b/tests/snapshots/compile_file_o_all__non_exhaustive_and.bend.snap index d75690cbd..b5509c980 100644 --- a/tests/snapshots/compile_file_o_all__non_exhaustive_and.bend.snap +++ b/tests/snapshots/compile_file_o_all__non_exhaustive_and.bend.snap @@ -5,4 +5,4 @@ input_file: tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend Errors: In tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend : In definition 'Bool.and': - Non-exhaustive pattern matching rule. Constructor 'Bool/F' of type 'Bool' not covered + Non-exhaustive pattern matching rule. Constructor 'Bool/False' of type 'Bool' not covered diff --git a/tests/snapshots/desugar_file__ask_branch.bend.snap b/tests/snapshots/desugar_file__ask_branch.bend.snap index 27e80ee09..13735593e 100644 --- a/tests/snapshots/desugar_file__ask_branch.bend.snap +++ b/tests/snapshots/desugar_file__ask_branch.bend.snap @@ -15,7 +15,13 @@ undefer: (((a -> a) -> b) -> b) (undefer) = λa (a λb b) unchecked main: Any -(main) = (IO/bind (Bool/T λa switch a { 0: (IO/wrap 0); _: λ* (IO/wrap 0); }) λb (b λc λd (c d) IO/wrap)) +(main) = (IO/bind (Bool/True λa switch a { 0: (IO/wrap 0); _: λ* (IO/wrap 0); }) λb (b λc λd (c d) IO/wrap)) + +Bool/True/tag: u24 +(Bool/True/tag) = 0 + +Bool/True: Bool +(Bool/True) = λa (a Bool/True/tag) IO/Done/tag: u24 (IO/Done/tag) = 0 @@ -29,18 +35,6 @@ IO/Call/tag: u24 IO/Call: ((u24, u24) -> String -> Any -> ((Result Any (IOError Any)) -> (IO a)) -> (IO a)) (IO/Call) = λa λb λc λd λe (e IO/Call/tag a b c d) -Bool/T/tag: u24 -(Bool/T/tag) = 0 - -Bool/T: Bool -(Bool/T) = λa (a Bool/T/tag) - -Bool/F/tag: u24 -(Bool/F/tag) = 1 - -Bool/F: Bool -(Bool/F) = λa (a Bool/F/tag) - IO/bind__C0: _ (IO/bind__C0) = λ* λa λb (undefer b a) diff --git a/tests/snapshots/desugar_file__mapper_syntax.bend.snap b/tests/snapshots/desugar_file__mapper_syntax.bend.snap index bc98f9b83..2ad776d58 100644 --- a/tests/snapshots/desugar_file__mapper_syntax.bend.snap +++ b/tests/snapshots/desugar_file__mapper_syntax.bend.snap @@ -2,6 +2,9 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/desugar_file/mapper_syntax.bend --- +Maybe/unwrap: ((Maybe a) -> a) +(Maybe/unwrap) = λa (a Maybe/unwrap__C0) + Map/empty: (Map a) (Map/empty) = Map/Leaf @@ -20,10 +23,22 @@ unreachable: Any unchecked main: Any (main) = let (c, d) = (Map/get (Map/map (Map/map (Map/set (Map/set Map/empty 0 3) 1 4) 1 λa (+ a 1)) 1 λb (* b 2)) 1); let (e, *) = (Map/get d 0); ((λf (+ f 1) 1), c, e) +Maybe/Some/tag: u24 +(Maybe/Some/tag) = 0 + +Maybe/Some: (a -> (Maybe a)) +(Maybe/Some) = λa λb (b Maybe/Some/tag a) + +Maybe/None/tag: u24 +(Maybe/None/tag) = 1 + +Maybe/None: (Maybe a) +(Maybe/None) = λa (a Maybe/None/tag) + Map/Node/tag: u24 (Map/Node/tag) = 0 -Map/Node: (a -> (Map a) -> (Map a) -> (Map a)) +Map/Node: ((Maybe a) -> (Map a) -> (Map a) -> (Map a)) (Map/Node) = λa λb λc λd (d Map/Node/tag a b c) Map/Leaf/tag: u24 @@ -33,16 +48,16 @@ Map/Leaf: (Map a) (Map/Leaf) = λa (a Map/Leaf/tag) Map/get__C0: _ -(Map/get__C0) = λa λb λc λd let (e, f) = (Map/get c (/ a 2)); (e, (Map/Node b f d)) +(Map/get__C0) = λa λb λc λd let (e, f) = (Map/get d (/ a 2)); (e, (Map/Node b f c)) Map/get__C1: _ -(Map/get__C1) = λ* λa λb λc λd let (e, f) = (Map/get d (/ a 2)); (e, (Map/Node b c f)) +(Map/get__C1) = λ* λa λb λc λd let (e, f) = (Map/get c (/ a 2)); (e, (Map/Node b f d)) Map/get__C2: _ -(Map/get__C2) = λa let {b c} = a; λd λe λf (switch (% b 2) { 0: Map/get__C0; _: Map/get__C1; } c d e f) +(Map/get__C2) = λa let {b c} = a; λd λe λf (switch (== (% b 2) 0) { 0: Map/get__C0; _: Map/get__C1; } c d e f) Map/get__C3: _ -(Map/get__C3) = λ* λ* λa let {b c} = a; λd λe (b, (Map/Node c d e)) +(Map/get__C3) = λ* λ* λa let {b c} = a; λd λe ((Maybe/unwrap b), (Map/Node c d e)) Map/get__C4: _ (Map/get__C4) = λa λb λc λd let {e f} = d; (switch (== 0 e) { 0: Map/get__C2; _: Map/get__C3; } f a b c) @@ -51,52 +66,55 @@ Map/get__C5: _ (Map/get__C5) = λa switch a { 0: Map/get__C4; _: λ* λ* (unreachable, Map/Leaf); } Map/map__C0: _ -(Map/map__C0) = λa λb λc λd λe (Map/Node c (Map/map d (/ a 2) b) e) +(Map/map__C0) = λa λb λc λd λe (Map/Node c d (Map/map e (/ a 2) b)) Map/map__C1: _ -(Map/map__C1) = λ* λa λb λc λd λe (Map/Node c d (Map/map e (/ a 2) b)) +(Map/map__C1) = λ* λa λb λc λd λe (Map/Node c (Map/map d (/ a 2) b) e) Map/map__C2: _ -(Map/map__C2) = λa let {b c} = a; λd λe λf λg (switch (% b 2) { 0: Map/map__C0; _: Map/map__C1; } c d e f g) +(Map/map__C2) = λa let {b c} = a; λd λe λf λg (switch (== (% b 2) 0) { 0: Map/map__C0; _: Map/map__C1; } c d e f g) Map/map__C3: _ -(Map/map__C3) = λ* λ* λa λb λc λd (Map/Node (a b) c d) +(Map/map__C3) = λ* λ* λa λb λc λd (Map/Node (Maybe/Some (a (Maybe/unwrap b))) c d) Map/map__C4: _ (Map/map__C4) = λa λb λc λd let {e f} = d; λg (switch (== 0 e) { 0: Map/map__C2; _: Map/map__C3; } f g a b c) Map/map__C5: _ -(Map/map__C5) = λa switch a { 0: Map/map__C4; _: λ* λ* λ* Map/Leaf; } +(Map/map__C5) = λa switch a { 0: Map/map__C4; _: λ* λ* λ* unreachable; } Map/set__C0: _ -(Map/set__C0) = λa λb λc λd λe (Map/Node c (Map/set d (/ a 2) b) e) +(Map/set__C0) = λa λb λc λd λe (Map/Node c d (Map/set e (/ a 2) b)) Map/set__C1: _ -(Map/set__C1) = λ* λa λb λc λd λe (Map/Node c d (Map/set e (/ a 2) b)) +(Map/set__C1) = λ* λa λb λc λd λe (Map/Node c (Map/set d (/ a 2) b) e) Map/set__C10: _ (Map/set__C10) = λa switch a { 0: Map/set__C8; _: Map/set__C9; } Map/set__C2: _ -(Map/set__C2) = λa let {b c} = a; λd λe λf λg (switch (% b 2) { 0: Map/set__C0; _: Map/set__C1; } c d e f g) +(Map/set__C2) = λa let {b c} = a; λd λe λf λg (switch (== (% b 2) 0) { 0: Map/set__C0; _: Map/set__C1; } c d e f g) Map/set__C3: _ -(Map/set__C3) = λ* λ* λa λ* λb λc (Map/Node a b c) +(Map/set__C3) = λ* λ* λa λ* λb λc (Map/Node (Maybe/Some a) b c) Map/set__C4: _ -(Map/set__C4) = λa λb (Map/Node unreachable (Map/set Map/Leaf (/ a 2) b) Map/Leaf) +(Map/set__C4) = λa λb (Map/Node Maybe/None Map/Leaf (Map/set Map/Leaf (/ a 2) b)) Map/set__C5: _ -(Map/set__C5) = λ* λa λb (Map/Node unreachable Map/Leaf (Map/set Map/Leaf (/ a 2) b)) +(Map/set__C5) = λ* λa λb (Map/Node Maybe/None (Map/set Map/Leaf (/ a 2) b) Map/Leaf) Map/set__C6: _ -(Map/set__C6) = λa let {b c} = a; λd (switch (% b 2) { 0: Map/set__C4; _: Map/set__C5; } c d) +(Map/set__C6) = λa let {b c} = a; λd (switch (== (% b 2) 0) { 0: Map/set__C4; _: Map/set__C5; } c d) Map/set__C7: _ -(Map/set__C7) = λ* λ* λa (Map/Node a Map/Leaf Map/Leaf) +(Map/set__C7) = λ* λ* λa (Map/Node (Maybe/Some a) Map/Leaf Map/Leaf) Map/set__C8: _ (Map/set__C8) = λa λb λc λd let {e f} = d; λg (switch (== 0 e) { 0: Map/set__C2; _: Map/set__C3; } f g a b c) Map/set__C9: _ (Map/set__C9) = λ* λa let {b c} = a; λd (switch (== 0 b) { 0: Map/set__C6; _: Map/set__C7; } c d) + +Maybe/unwrap__C0: _ +(Maybe/unwrap__C0) = λa switch a { 0: λb b; _: λ* unreachable; } diff --git a/tests/snapshots/encode_pattern_match__and3.bend.snap b/tests/snapshots/encode_pattern_match__and3.bend.snap index 1b6a84c82..952a20279 100644 --- a/tests/snapshots/encode_pattern_match__and3.bend.snap +++ b/tests/snapshots/encode_pattern_match__and3.bend.snap @@ -4,32 +4,32 @@ input_file: tests/golden_tests/encode_pattern_match/and3.bend --- Scott unchecked And: Any -(And) = λa let (b, c, d) = a; (b λe λf (e λg (g Bool/T Bool/F) λ* Bool/F f) λ* λ* Bool/F c d) +(And) = λa let (b, c, d) = a; (b λe λf (e λg (g Bool/True Bool/False) λ* Bool/False f) λ* λ* Bool/False c d) unchecked main: Any -(main) = (And (Bool/F, Bool/T, Bool/F)) +(main) = (And (Bool/False, Bool/True, Bool/False)) -Bool/T: Bool -(Bool/T) = λa λ* a +Bool/True: Bool +(Bool/True) = λa λ* a -Bool/F: Bool -(Bool/F) = λ* λb b +Bool/False: Bool +(Bool/False) = λ* λb b NumScott unchecked And: Any -(And) = λa let (b, c, d) = a; (b λe switch e { 0: λf λg (f λh switch h { 0: λi (i λj switch j { 0: Bool/T; _: λ* Bool/F; }); _: λ* λ* Bool/F; } g); _: λ* λ* λ* Bool/F; } c d) +(And) = λa let (b, c, d) = a; (b λe switch e { 0: λf λg (f λh switch h { 0: λi (i λj switch j { 0: Bool/True; _: λ* Bool/False; }); _: λ* λ* Bool/False; } g); _: λ* λ* λ* Bool/False; } c d) unchecked main: Any -(main) = (And (Bool/F, Bool/T, Bool/F)) +(main) = (And (Bool/False, Bool/True, Bool/False)) -Bool/T/tag: _ -(Bool/T/tag) = 0 +Bool/True/tag: _ +(Bool/True/tag) = 0 -Bool/T: Bool -(Bool/T) = λa (a Bool/T/tag) +Bool/True: Bool +(Bool/True) = λa (a Bool/True/tag) -Bool/F/tag: _ -(Bool/F/tag) = 1 +Bool/False/tag: _ +(Bool/False/tag) = 1 -Bool/F: Bool -(Bool/F) = λa (a Bool/F/tag) +Bool/False: Bool +(Bool/False) = λa (a Bool/False/tag) diff --git a/tests/snapshots/encode_pattern_match__bool_tup.bend.snap b/tests/snapshots/encode_pattern_match__bool_tup.bend.snap index ae4e71b54..c6274d188 100644 --- a/tests/snapshots/encode_pattern_match__bool_tup.bend.snap +++ b/tests/snapshots/encode_pattern_match__bool_tup.bend.snap @@ -4,32 +4,32 @@ input_file: tests/golden_tests/encode_pattern_match/bool_tup.bend --- Scott unchecked foo: Any -(foo) = λa let (b, c) = a; (b λd d λ* Bool/F c) +(foo) = λa let (b, c) = a; (b λd d λ* Bool/False c) unchecked main: Any -(main) = (foo (Bool/F, Bool/T)) +(main) = (foo (Bool/False, Bool/True)) -Bool/T: Bool -(Bool/T) = λa λ* a +Bool/True: Bool +(Bool/True) = λa λ* a -Bool/F: Bool -(Bool/F) = λ* λb b +Bool/False: Bool +(Bool/False) = λ* λb b NumScott unchecked foo: Any -(foo) = λa let (b, c) = a; (b λd switch d { 0: λe e; _: λ* λ* Bool/F; } c) +(foo) = λa let (b, c) = a; (b λd switch d { 0: λe e; _: λ* λ* Bool/False; } c) unchecked main: Any -(main) = (foo (Bool/F, Bool/T)) +(main) = (foo (Bool/False, Bool/True)) -Bool/T/tag: _ -(Bool/T/tag) = 0 +Bool/True/tag: _ +(Bool/True/tag) = 0 -Bool/T: Bool -(Bool/T) = λa (a Bool/T/tag) +Bool/True: Bool +(Bool/True) = λa (a Bool/True/tag) -Bool/F/tag: _ -(Bool/F/tag) = 1 +Bool/False/tag: _ +(Bool/False/tag) = 1 -Bool/F: Bool -(Bool/F) = λa (a Bool/F/tag) +Bool/False: Bool +(Bool/False) = λa (a Bool/False/tag) diff --git a/tests/snapshots/encode_pattern_match__common.bend.snap b/tests/snapshots/encode_pattern_match__common.bend.snap index 8ba0880f0..d01e03d16 100644 --- a/tests/snapshots/encode_pattern_match__common.bend.snap +++ b/tests/snapshots/encode_pattern_match__common.bend.snap @@ -27,12 +27,6 @@ List_/Cons: (Any -> Any -> List_) List_/Nil: List_ (List_/Nil) = λ* λb b -Bool/True: Bool -(Bool/True) = λa λ* a - -Bool/False: Bool -(Bool/False) = λ* λb b - Light/Red: Light (Light/Red) = λa λ* λ* a @@ -103,18 +97,6 @@ List_/Nil/tag: _ List_/Nil: List_ (List_/Nil) = λa (a List_/Nil/tag) -Bool/True/tag: _ -(Bool/True/tag) = 0 - -Bool/True: Bool -(Bool/True) = λa (a Bool/True/tag) - -Bool/False/tag: _ -(Bool/False/tag) = 1 - -Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) - Light/Red/tag: _ (Light/Red/tag) = 0 diff --git a/tests/snapshots/encode_pattern_match__definition_merge.bend.snap b/tests/snapshots/encode_pattern_match__definition_merge.bend.snap index ba5305920..2a753e7fb 100644 --- a/tests/snapshots/encode_pattern_match__definition_merge.bend.snap +++ b/tests/snapshots/encode_pattern_match__definition_merge.bend.snap @@ -12,12 +12,6 @@ Either/Left: (Any -> Either) Either/Right: (Any -> Either) (Either/Right) = λa λ* λc (c a) -Bool/True: Bool -(Bool/True) = λa λ* a - -Bool/False: Bool -(Bool/False) = λ* λb b - NumScott unchecked Foo: Any (Foo) = λa (a λb switch b { 0: λc (c λd switch d { 0: λe (e λh switch h { 0: λi (i λj switch j { 0: 1; _: λ* 1; }); _: λ* λk (k λl switch l { 0: 2; _: λ* 2; }); }); _: λ* λm (m λp switch p { 0: λq (q λr switch r { 0: 1; _: λ* 1; }); _: λ* λs (s λt switch t { 0: 2; _: λ* 2; }); }); }); _: λ* λu (u λv switch v { 0: λw (w λz switch z { 0: λab (ab λbb switch bb { 0: 3; _: λ* 3; }); _: λ* λcb (cb λdb switch db { 0: 3; _: λ* 3; }); }); _: λ* λeb (eb λhb switch hb { 0: λib (ib λjb switch jb { 0: 3; _: λ* 3; }); _: λ* λkb (kb λlb switch lb { 0: 3; _: λ* 3; }); }); }); }) @@ -33,15 +27,3 @@ Either/Right/tag: _ Either/Right: (Any -> Either) (Either/Right) = λa λb (b Either/Right/tag a) - -Bool/True/tag: _ -(Bool/True/tag) = 0 - -Bool/True: Bool -(Bool/True) = λa (a Bool/True/tag) - -Bool/False/tag: _ -(Bool/False/tag) = 1 - -Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) diff --git a/tests/snapshots/encode_pattern_match__full_map.bend.snap b/tests/snapshots/encode_pattern_match__full_map.bend.snap index 1bc0768c6..741188aef 100644 --- a/tests/snapshots/encode_pattern_match__full_map.bend.snap +++ b/tests/snapshots/encode_pattern_match__full_map.bend.snap @@ -3,8 +3,11 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/encode_pattern_match/full_map.bend --- Scott +Maybe/unwrap: ((Maybe T) -> T) +(Maybe/unwrap) = λa (a λb b unreachable) + Map/get: ((Map T) -> u24 -> (T, (Map T))) -(Map/get) = λa (a λb let {b b_2 b_3 b_4} = b; λc let {c c_2 c_3} = c; λd let {d d_2 d_3} = d; λe let {e e_2 e_3 e_4} = e; switch (== 0 e) { 0: switch (% e_2 2) { 0: let (f, g) = (Map/get c (/ e_3 2)); (f, (Map/Node b g d)); _: λ* let (i, j) = (Map/get d_2 (/ e_4 2)); (i, (Map/Node b_2 c_2 j)); }; _: λ* (b_3, (Map/Node b_4 c_3 d_3)); } λ* (unreachable, Map/Leaf)) +(Map/get) = λa (a λb let {b b_2 b_3 b_4} = b; λc let {c c_2 c_3} = c; λd let {d d_2 d_3} = d; λe let {e e_2 e_3 e_4} = e; switch (== 0 e) { 0: switch (== (% e_2 2) 0) { 0: let (f, g) = (Map/get d (/ e_3 2)); (f, (Map/Node b g c)); _: λ* let (i, j) = (Map/get c_2 (/ e_4 2)); (i, (Map/Node b_2 j d_2)); }; _: λ* ((Maybe/unwrap b_3), (Map/Node b_4 c_3 d_3)); } λ* (unreachable, Map/Leaf)) unreachable: Any (unreachable) = * @@ -21,7 +24,7 @@ unchecked test: (Any -> Any) unchecked main: Any (main) = (test fullMap) -Map/Node: (T -> (Map T) -> (Map T) -> (Map T)) +Map/Node: ((Maybe T) -> (Map T) -> (Map T) -> (Map T)) (Map/Node) = λa λb λc λd λ* (d a b c) Map/Leaf: (Map T) @@ -34,8 +37,11 @@ unchecked test__bend0: _ (test__bend0) = λa let {a a_2 a_3} = a; switch (< a 1000) { 0: λ* 0; _: λ* λd let (e, f) = (Map/get d (% (prng a_2) 4096)); (+ e (test__bend0 (+ a_3 1) f)); } NumScott +Maybe/unwrap: ((Maybe T) -> T) +(Maybe/unwrap) = λa (a λb switch b { 0: λc c; _: λ* unreachable; }) + Map/get: ((Map T) -> u24 -> (T, (Map T))) -(Map/get) = λa (a λb switch b { 0: λc let {c c_2 c_3 c_4} = c; λd let {d d_2 d_3} = d; λe let {e e_2 e_3} = e; λf let {f f_2 f_3 f_4} = f; switch (== 0 f) { 0: switch (% f_2 2) { 0: let (g, h) = (Map/get d (/ f_3 2)); (g, (Map/Node c h e)); _: λ* let (j, k) = (Map/get e_2 (/ f_4 2)); (j, (Map/Node c_2 d_2 k)); }; _: λ* (c_3, (Map/Node c_4 d_3 e_3)); }; _: λ* λ* (unreachable, Map/Leaf); }) +(Map/get) = λa (a λb switch b { 0: λc let {c c_2 c_3 c_4} = c; λd let {d d_2 d_3} = d; λe let {e e_2 e_3} = e; λf let {f f_2 f_3 f_4} = f; switch (== 0 f) { 0: switch (== (% f_2 2) 0) { 0: let (g, h) = (Map/get e (/ f_3 2)); (g, (Map/Node c h d)); _: λ* let (j, k) = (Map/get d_2 (/ f_4 2)); (j, (Map/Node c_2 k e_2)); }; _: λ* ((Maybe/unwrap c_3), (Map/Node c_4 d_3 e_3)); }; _: λ* λ* (unreachable, Map/Leaf); }) unreachable: Any (unreachable) = * @@ -55,7 +61,7 @@ unchecked main: Any Map/Node/tag: _ (Map/Node/tag) = 0 -Map/Node: (T -> (Map T) -> (Map T) -> (Map T)) +Map/Node: ((Maybe T) -> (Map T) -> (Map T) -> (Map T)) (Map/Node) = λa λb λc λd (d Map/Node/tag a b c) Map/Leaf/tag: _ diff --git a/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap b/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap index d1e56e142..90e833ca3 100644 --- a/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap +++ b/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap @@ -24,12 +24,6 @@ unchecked MergePair: Any unchecked Merge: Any (Merge) = λa λb (b λc λd λe λf (f λh let {h h_2 h_3} = h; λi let {i i_2} = i; λj let {j j_2 j_3} = j; λk let {k k_2 k_3} = k; λl let {l l_2} = l; (If (j k h) (List_/Cons k_2 (Merge j_2 l (List_/Cons h_2 i))) (List_/Cons h_3 (Merge j_3 (List_/Cons k_3 l_2) i_2))) λ* λp λq (List_/Cons p q) e c d) λ* λs s a) -Bool/True: Bool -(Bool/True) = λa λ* a - -Bool/False: Bool -(Bool/False) = λ* λb b - List_/Cons: (Any -> Any -> List_) (List_/Cons) = λa λb λc λ* (c a b) @@ -58,18 +52,6 @@ unchecked MergePair: Any unchecked Merge: Any (Merge) = λa λb (b λc switch c { 0: λd λe λf λg (g λi switch i { 0: λj let {j j_2 j_3} = j; λk let {k k_2} = k; λl let {l l_2 l_3} = l; λm let {m m_2 m_3} = m; λn let {n n_2} = n; (If (l m j) (List_/Cons m_2 (Merge l_2 n (List_/Cons j_2 k))) (List_/Cons j_3 (Merge l_3 (List_/Cons m_3 n_2) k_2))); _: λ* λ* λr λs (List_/Cons r s); } f d e); _: λ* λ* λu u; } a) -Bool/True/tag: _ -(Bool/True/tag) = 0 - -Bool/True: Bool -(Bool/True) = λa (a Bool/True/tag) - -Bool/False/tag: _ -(Bool/False/tag) = 1 - -Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) - List_/Cons/tag: _ (List_/Cons/tag) = 0 diff --git a/tests/snapshots/encode_pattern_match__match_adt_unscoped_lambda.bend.snap b/tests/snapshots/encode_pattern_match__match_adt_unscoped_lambda.bend.snap index d53c30f3c..812c3186e 100644 --- a/tests/snapshots/encode_pattern_match__match_adt_unscoped_lambda.bend.snap +++ b/tests/snapshots/encode_pattern_match__match_adt_unscoped_lambda.bend.snap @@ -2,28 +2,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/encode_pattern_match/match_adt_unscoped_lambda.bend --- -Scott -unchecked main: Any -(main) = (Maybe/Some 1 λ$x * λa a $x) - -Maybe/None: Maybe -(Maybe/None) = λa λ* a - -Maybe/Some: (Any -> Maybe) -(Maybe/Some) = λa λ* λc (c a) - -NumScott -unchecked main: Any -(main) = (Maybe/Some 1 λa switch a { 0: λ$x *; _: λ* λb b; } $x) - -Maybe/None/tag: _ -(Maybe/None/tag) = 0 - -Maybe/None: Maybe -(Maybe/None) = λa (a Maybe/None/tag) - -Maybe/Some/tag: _ -(Maybe/Some/tag) = 1 - -Maybe/Some: (Any -> Maybe) -(Maybe/Some) = λa λb (b Maybe/Some/tag a) +Errors: +In tests/golden_tests/encode_pattern_match/match_adt_unscoped_lambda.bend : +In definition 'main': + Unbound variable 'x.value'. diff --git a/tests/snapshots/encode_pattern_match__match_adt_unscoped_var.bend.snap b/tests/snapshots/encode_pattern_match__match_adt_unscoped_var.bend.snap index d79b401c3..ab75272bc 100644 --- a/tests/snapshots/encode_pattern_match__match_adt_unscoped_var.bend.snap +++ b/tests/snapshots/encode_pattern_match__match_adt_unscoped_var.bend.snap @@ -4,38 +4,29 @@ input_file: tests/golden_tests/encode_pattern_match/match_adt_unscoped_var.bend --- Scott unchecked Foo: Any -(Foo) = λ$x (Maybe/Some 1 $x λa a) +(Foo) = λ$x (Maybe/Some 1 λa a $x) unchecked Bar: Any -(Bar) = (Maybe/Some 1 $x λa a λ$x *) +(Bar) = (Maybe/Some 1 λa a $x λ$x *) unchecked main: Any (main) = * -Maybe/None: Maybe -(Maybe/None) = λa λ* a - -Maybe/Some: (Any -> Maybe) -(Maybe/Some) = λa λ* λc (c a) +Maybe/Some: (T -> (Maybe T)) +(Maybe/Some) = λa λb λ* (b a) NumScott unchecked Foo: Any -(Foo) = λ$x (Maybe/Some 1 λa switch a { 0: $x; _: λ* λb b; }) +(Foo) = λ$x (Maybe/Some 1 λa switch a { 0: λb b; _: λ* $x; }) unchecked Bar: Any -(Bar) = (Maybe/Some 1 λa switch a { 0: $x; _: λ* λb b; } λ$x *) +(Bar) = (Maybe/Some 1 λa switch a { 0: λb b; _: λ* $x; } λ$x *) unchecked main: Any (main) = * -Maybe/None/tag: _ -(Maybe/None/tag) = 0 - -Maybe/None: Maybe -(Maybe/None) = λa (a Maybe/None/tag) - Maybe/Some/tag: _ -(Maybe/Some/tag) = 1 +(Maybe/Some/tag) = 0 -Maybe/Some: (Any -> Maybe) +Maybe/Some: (T -> (Maybe T)) (Maybe/Some) = λa λb (b Maybe/Some/tag a) diff --git a/tests/snapshots/encode_pattern_match__var_only.bend.snap b/tests/snapshots/encode_pattern_match__var_only.bend.snap index 9780a609b..01e50e07b 100644 --- a/tests/snapshots/encode_pattern_match__var_only.bend.snap +++ b/tests/snapshots/encode_pattern_match__var_only.bend.snap @@ -9,27 +9,9 @@ unchecked Foo: Any unchecked main: Any (main) = λ* Foo -Bool/False: Bool -(Bool/False) = λa λ* a - -Bool/True: Bool -(Bool/True) = λ* λb b - NumScott unchecked Foo: Any (Foo) = λa λ* λc (c a) unchecked main: Any (main) = λ* Foo - -Bool/False/tag: _ -(Bool/False/tag) = 0 - -Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) - -Bool/True/tag: _ -(Bool/True/tag) = 1 - -Bool/True: Bool -(Bool/True) = λa (a Bool/True/tag) diff --git a/tests/snapshots/parse_file__imp_map.bend.snap b/tests/snapshots/parse_file__imp_map.bend.snap index 0aec833ca..385269bc1 100644 --- a/tests/snapshots/parse_file__imp_map.bend.snap +++ b/tests/snapshots/parse_file__imp_map.bend.snap @@ -2,14 +2,17 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/parse_file/imp_map.bend --- +Maybe/unwrap: ((Maybe T) -> T) +(Maybe/unwrap m) = match m = m { Maybe/Some: m.val; Maybe/None: unreachable; } + Map/empty: (Map T) (Map/empty) = Map/Leaf Map/get: ((Map T) -> u24 -> (T, (Map T))) -(Map/get map key) = match map = map { Map/Leaf: (unreachable, map); Map/Node: switch _ = (== 0 key) { 0: switch _ = (% key 2) { 0: let (got, rest) = (Map/get map.left (/ key 2)); (got, (Map/Node map.value rest map.right)); _ _-1: let (got, rest) = (Map/get map.right (/ key 2)); (got, (Map/Node map.value map.left rest)); }; _ _-1: (map.value, map); }; } +(Map/get map key) = match map = map { Map/Node: switch %pred = (== 0 key) { 0: switch %pred = (== (% key 2) 0) { 0: let (got, rest) = (Map/get map.right (/ key 2)); (got, (Map/Node map.value rest map.left)); _ %pred-1: let (got, rest) = (Map/get map.left (/ key 2)); (got, (Map/Node map.value rest map.right)); }; _ %pred-1: ((Maybe/unwrap map.value), map); }; Map/Leaf: (unreachable, map); } Map/set: ((Map T) -> u24 -> T -> (Map T)) -(Map/set map key value) = match map = map { Map/Node: switch _ = (== 0 key) { 0: switch _ = (% key 2) { 0: (Map/Node map.value (Map/set map.left (/ key 2) value) map.right); _ _-1: (Map/Node map.value map.left (Map/set map.right (/ key 2) value)); }; _ _-1: (Map/Node value map.left map.right); }; Map/Leaf: switch _ = (== 0 key) { 0: switch _ = (% key 2) { 0: (Map/Node unreachable (Map/set Map/Leaf (/ key 2) value) Map/Leaf); _ _-1: (Map/Node unreachable Map/Leaf (Map/set Map/Leaf (/ key 2) value)); }; _ _-1: (Map/Node value Map/Leaf Map/Leaf); }; } +(Map/set map key value) = match map = map { Map/Node: switch %pred = (== 0 key) { 0: switch %pred = (== (% key 2) 0) { 0: (Map/Node map.value map.left (Map/set map.right (/ key 2) value)); _ %pred-1: (Map/Node map.value (Map/set map.left (/ key 2) value) map.right); }; _ %pred-1: (Map/Node (Maybe/Some value) map.left map.right); }; Map/Leaf: switch %pred = (== 0 key) { 0: switch %pred = (== (% key 2) 0) { 0: (Map/Node Maybe/None Map/Leaf (Map/set Map/Leaf (/ key 2) value)); _ %pred-1: (Map/Node Maybe/None (Map/set Map/Leaf (/ key 2) value) Map/Leaf); }; _ %pred-1: (Map/Node (Maybe/Some value) Map/Leaf Map/Leaf); }; } unreachable: Any (unreachable) = * @@ -17,10 +20,22 @@ unreachable: Any unchecked main: Any (main) = let x = (Map/set (Map/set Map/empty 2 1) 3 2); let (map/get%1, x) = (Map/get x 2); let y = (id map/get%1); let z = 4; let x = (Map/set x z 4); let (map/get%0, x) = (Map/get x z); (+ y map/get%0) +Maybe/Some/tag: _ +(Maybe/Some/tag) = 0 + +Maybe/Some: (T -> (Maybe T)) +(Maybe/Some) = λval λ%x (%x Maybe/Some/tag val) + +Maybe/None/tag: _ +(Maybe/None/tag) = 1 + +Maybe/None: (Maybe T) +(Maybe/None) = λ%x (%x Maybe/None/tag) + Map/Node/tag: _ (Map/Node/tag) = 0 -Map/Node: (T -> (Map T) -> (Map T) -> (Map T)) +Map/Node: ((Maybe T) -> (Map T) -> (Map T) -> (Map T)) (Map/Node) = λvalue λleft λright λ%x (%x Map/Node/tag value left right) Map/Leaf/tag: _ diff --git a/tests/snapshots/parse_file__imp_program.bend.snap b/tests/snapshots/parse_file__imp_program.bend.snap index 6ff1327a6..57220e61c 100644 --- a/tests/snapshots/parse_file__imp_program.bend.snap +++ b/tests/snapshots/parse_file__imp_program.bend.snap @@ -2,14 +2,17 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/parse_file/imp_program.bend --- +Maybe/unwrap: ((Maybe T) -> T) +(Maybe/unwrap m) = match m = m { Maybe/Some: m.val; Maybe/None: unreachable; } + Map/empty: (Map T) (Map/empty) = Map/Leaf Map/get: ((Map T) -> u24 -> (T, (Map T))) -(Map/get map key) = match map = map { Map/Leaf: (unreachable, map); Map/Node: switch _ = (== 0 key) { 0: switch _ = (% key 2) { 0: let (got, rest) = (Map/get map.left (/ key 2)); (got, (Map/Node map.value rest map.right)); _ _-1: let (got, rest) = (Map/get map.right (/ key 2)); (got, (Map/Node map.value map.left rest)); }; _ _-1: (map.value, map); }; } +(Map/get map key) = match map = map { Map/Node: switch %pred = (== 0 key) { 0: switch %pred = (== (% key 2) 0) { 0: let (got, rest) = (Map/get map.right (/ key 2)); (got, (Map/Node map.value rest map.left)); _ %pred-1: let (got, rest) = (Map/get map.left (/ key 2)); (got, (Map/Node map.value rest map.right)); }; _ %pred-1: ((Maybe/unwrap map.value), map); }; Map/Leaf: (unreachable, map); } Map/set: ((Map T) -> u24 -> T -> (Map T)) -(Map/set map key value) = match map = map { Map/Node: switch _ = (== 0 key) { 0: switch _ = (% key 2) { 0: (Map/Node map.value (Map/set map.left (/ key 2) value) map.right); _ _-1: (Map/Node map.value map.left (Map/set map.right (/ key 2) value)); }; _ _-1: (Map/Node value map.left map.right); }; Map/Leaf: switch _ = (== 0 key) { 0: switch _ = (% key 2) { 0: (Map/Node unreachable (Map/set Map/Leaf (/ key 2) value) Map/Leaf); _ _-1: (Map/Node unreachable Map/Leaf (Map/set Map/Leaf (/ key 2) value)); }; _ _-1: (Map/Node value Map/Leaf Map/Leaf); }; } +(Map/set map key value) = match map = map { Map/Node: switch %pred = (== 0 key) { 0: switch %pred = (== (% key 2) 0) { 0: (Map/Node map.value map.left (Map/set map.right (/ key 2) value)); _ %pred-1: (Map/Node map.value (Map/set map.left (/ key 2) value) map.right); }; _ %pred-1: (Map/Node (Maybe/Some value) map.left map.right); }; Map/Leaf: switch %pred = (== 0 key) { 0: switch %pred = (== (% key 2) 0) { 0: (Map/Node Maybe/None Map/Leaf (Map/set Map/Leaf (/ key 2) value)); _ %pred-1: (Map/Node Maybe/None (Map/set Map/Leaf (/ key 2) value) Map/Leaf); }; _ %pred-1: (Map/Node (Maybe/Some value) Map/Leaf Map/Leaf); }; } unreachable: Any (unreachable) = * @@ -71,10 +74,28 @@ List/Cons/tag: _ List/Cons: (T -> (List T) -> (List T)) (List/Cons) = λhead λtail λ%x (%x List/Cons/tag head tail) +Bool/True/tag: _ +(Bool/True/tag) = 0 + +Bool/True: Bool +(Bool/True) = λ%x (%x Bool/True/tag) + +Maybe/Some/tag: _ +(Maybe/Some/tag) = 0 + +Maybe/Some: (T -> (Maybe T)) +(Maybe/Some) = λval λ%x (%x Maybe/Some/tag val) + +Maybe/None/tag: _ +(Maybe/None/tag) = 1 + +Maybe/None: (Maybe T) +(Maybe/None) = λ%x (%x Maybe/None/tag) + Map/Node/tag: _ (Map/Node/tag) = 0 -Map/Node: (T -> (Map T) -> (Map T) -> (Map T)) +Map/Node: ((Maybe T) -> (Map T) -> (Map T) -> (Map T)) (Map/Node) = λvalue λleft λright λ%x (%x Map/Node/tag value left right) Map/Leaf/tag: _ @@ -88,15 +109,3 @@ Point/Point/tag: _ Point/Point: (Any -> Any -> Point) (Point/Point) = λx λy λ%x (%x Point/Point/tag x y) - -Bool/True/tag: _ -(Bool/True/tag) = 0 - -Bool/True: Bool -(Bool/True) = λ%x (%x Bool/True/tag) - -Bool/False/tag: _ -(Bool/False/tag) = 1 - -Bool/False: Bool -(Bool/False) = λ%x (%x Bool/False/tag) diff --git a/tests/snapshots/run_file__filter_bool_id.bend.snap b/tests/snapshots/run_file__filter_bool_id.bend.snap index 760ed391e..8b995e9c2 100644 --- a/tests/snapshots/run_file__filter_bool_id.bend.snap +++ b/tests/snapshots/run_file__filter_bool_id.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/filter_bool_id.bend --- NumScott: -[Bool/T] +[Bool/True] Scott: -[Bool/T] +[Bool/True] diff --git a/tests/snapshots/run_file__nested_map_get.bend.snap b/tests/snapshots/run_file__nested_map_get.bend.snap index 51bd56561..77a296892 100644 --- a/tests/snapshots/run_file__nested_map_get.bend.snap +++ b/tests/snapshots/run_file__nested_map_get.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/nested_map_get.bend --- NumScott: -43 +84 Scott: -43 +84 diff --git a/tests/snapshots/run_file__nested_map_set.bend.snap b/tests/snapshots/run_file__nested_map_set.bend.snap index ea6941a0c..5b069d9f7 100644 --- a/tests/snapshots/run_file__nested_map_set.bend.snap +++ b/tests/snapshots/run_file__nested_map_set.bend.snap @@ -3,7 +3,7 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/run_file/nested_map_set.bend --- NumScott: -100 +* Scott: -100 +* diff --git a/tests/snapshots/run_file__unbound_wrap.bend.snap b/tests/snapshots/run_file__unbound_wrap.bend.snap index 552967160..cecea2bc8 100644 --- a/tests/snapshots/run_file__unbound_wrap.bend.snap +++ b/tests/snapshots/run_file__unbound_wrap.bend.snap @@ -4,5 +4,5 @@ input_file: tests/golden_tests/run_file/unbound_wrap.bend --- Errors: In tests/golden_tests/run_file/unbound_wrap.bend : -In definition 'main': - Reference to undefined function 'Maybe/wrap' +In definition 'Maybe/bind': + Unbound variable 'val.x'. diff --git a/tests/snapshots/simplify_matches__double_unwrap_maybe.bend.snap b/tests/snapshots/simplify_matches__double_unwrap_maybe.bend.snap index 601e2008e..2d0fe9449 100644 --- a/tests/snapshots/simplify_matches__double_unwrap_maybe.bend.snap +++ b/tests/snapshots/simplify_matches__double_unwrap_maybe.bend.snap @@ -11,11 +11,11 @@ unchecked Main: Any Maybe/Some/tag: _ (Maybe/Some/tag) = 0 -Maybe/Some: (Any -> Maybe) +Maybe/Some: (T -> (Maybe T)) (Maybe/Some) = λa λb (b Maybe/Some/tag a) Maybe/None/tag: _ (Maybe/None/tag) = 1 -Maybe/None: Maybe +Maybe/None: (Maybe T) (Maybe/None) = λa (a Maybe/None/tag)