From 8f6763665ae28a23077eabc5f83766ec24267196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20V=C3=A9rit=C3=A9?= Date: Mon, 9 Dec 2024 18:53:12 +0100 Subject: [PATCH] Updates builtin type Map so that it stores Maybes in its nodes. --- examples/example_fun.bend | 2 +- examples/parallel_and.bend | 2 ++ src/fun/builtins.bend | 8 +------- .../compile_file_o_all/list_merge_sort.bend | 2 ++ .../compile_file_o_all/non_exhaustive_and.bend | 1 + .../golden_tests/desugar_file/ask_branch.bend | 1 + .../encode_pattern_match/and3.bend | 1 + .../encode_pattern_match/bool_tup.bend | 1 + .../encode_pattern_match/definition_merge.bend | 1 + .../encode_pattern_match/list_merge_sort.bend | 1 + .../mutual_recursion/odd_even.bend | 1 + tests/golden_tests/parse_file/imp_program.bend | 1 + tests/golden_tests/run_file/example.bend | 1 + .../golden_tests/run_file/filter_bool_id.bend | 2 ++ tests/golden_tests/run_file/mixed_syntax.bend | 1 + .../run_file/unscoped_never_used.bend | 1 + .../desugar_file__ask_branch.bend.snap | 18 ++++++++++++------ ...e_pattern_match__definition_merge.bend.snap | 18 ++++++++++++++++++ ...de_pattern_match__list_merge_sort.bend.snap | 18 ++++++++++++++++++ .../parse_file__imp_program.bend.snap | 12 ++++++++++++ 20 files changed, 79 insertions(+), 14 deletions(-) diff --git a/examples/example_fun.bend b/examples/example_fun.bend index 4e1b73568..dbac0765f 100644 --- a/examples/example_fun.bend +++ b/examples/example_fun.bend @@ -44,7 +44,7 @@ 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 (Option.unwrap_or (Option/Some val) *) = val diff --git a/examples/parallel_and.bend b/examples/parallel_and.bend index 2dcd9cdd6..1860d6e31 100644 --- a/examples/parallel_and.bend +++ b/examples/parallel_and.bend @@ -1,3 +1,5 @@ +type Bool = True | False + # This program allocates a tree with True at the leaves then parallel ANDs them. def and(a: Bool, b: Bool) -> Bool: match a: diff --git a/src/fun/builtins.bend b/src/fun/builtins.bend index 3495616bb..253c9ce42 100644 --- a/src/fun/builtins.bend +++ b/src/fun/builtins.bend @@ -169,13 +169,7 @@ def Tree/reverse(tree: Tree(T)) -> Tree(T): return !tree.value case Tree/Node: return ![tree.right, tree.left] - -# BOOL Impl -type Bool: - True - False - - + # MAYBE Impl type Maybe(T): 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 9528ff9b8..26f9fdb43 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,5 +1,7 @@ type List_ = (Cons head tail) | Nil +type Bool = True | False + If Bool/True then else = then If Bool/False then else = else 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 c897858ec..accebf157 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,3 +1,4 @@ +type Bool = True | False Bool.and Bool/True Bool/True = Bool/True Bool.and Bool/False Bool/False = Bool/False diff --git a/tests/golden_tests/desugar_file/ask_branch.bend b/tests/golden_tests/desugar_file/ask_branch.bend index 98f5871c6..667061fbe 100644 --- a/tests/golden_tests/desugar_file/ask_branch.bend +++ b/tests/golden_tests/desugar_file/ask_branch.bend @@ -1,3 +1,4 @@ +type Bool = True | False def main: with IO: match _ = Bool/True: diff --git a/tests/golden_tests/encode_pattern_match/and3.bend b/tests/golden_tests/encode_pattern_match/and3.bend index b6f465f08..b7ab81a26 100644 --- a/tests/golden_tests/encode_pattern_match/and3.bend +++ b/tests/golden_tests/encode_pattern_match/and3.bend @@ -1,3 +1,4 @@ +type Bool = True | False And (Bool/True, Bool/True, Bool/True) = Bool/True And * = 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 9136cfb76..bdf8dae15 100644 --- a/tests/golden_tests/encode_pattern_match/bool_tup.bend +++ b/tests/golden_tests/encode_pattern_match/bool_tup.bend @@ -1,3 +1,4 @@ +type Bool = True | False foo (Bool/True, x) = x foo * = Bool/False diff --git a/tests/golden_tests/encode_pattern_match/definition_merge.bend b/tests/golden_tests/encode_pattern_match/definition_merge.bend index c63c0aaca..51e6ed7db 100644 --- a/tests/golden_tests/encode_pattern_match/definition_merge.bend +++ b/tests/golden_tests/encode_pattern_match/definition_merge.bend @@ -1,3 +1,4 @@ +type Bool = True | False type Either = (Left value) | (Right value) Foo (Either/Left Bool/False) (Either/Left Bool/False) = 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 dcf3d3899..c1e13e363 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,5 @@ type List_ = (Cons head tail) | Nil +type Bool = True | False If Bool/True then else = then If Bool/False then else = else diff --git a/tests/golden_tests/mutual_recursion/odd_even.bend b/tests/golden_tests/mutual_recursion/odd_even.bend index 600b085a5..c40d278a1 100644 --- a/tests/golden_tests/mutual_recursion/odd_even.bend +++ b/tests/golden_tests/mutual_recursion/odd_even.bend @@ -1,3 +1,4 @@ +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 f9bf6727a..e56648956 100644 --- a/tests/golden_tests/parse_file/imp_program.bend +++ b/tests/golden_tests/parse_file/imp_program.bend @@ -1,5 +1,6 @@ type Point: Point { x, y } +type Bool = True | False def symbols(): diff --git a/tests/golden_tests/run_file/example.bend b/tests/golden_tests/run_file/example.bend index 92a1124a3..fe374cd63 100644 --- a/tests/golden_tests/run_file/example.bend +++ b/tests/golden_tests/run_file/example.bend @@ -27,6 +27,7 @@ # 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 ba2e6b3c7..1b554bfb8 100644 --- a/tests/golden_tests/run_file/filter_bool_id.bend +++ b/tests/golden_tests/run_file/filter_bool_id.bend @@ -1,3 +1,5 @@ +type Bool = True | False + def filter(f, ls): match ls: case List/Nil: diff --git a/tests/golden_tests/run_file/mixed_syntax.bend b/tests/golden_tests/run_file/mixed_syntax.bend index 6b47e8b56..20d37256b 100644 --- a/tests/golden_tests/run_file/mixed_syntax.bend +++ b/tests/golden_tests/run_file/mixed_syntax.bend @@ -1,4 +1,5 @@ type MyTree = (node ~lft ~rgt) | (leaf val) +type Bool = True | False def tree_xor(tree): fold tree: diff --git a/tests/golden_tests/run_file/unscoped_never_used.bend b/tests/golden_tests/run_file/unscoped_never_used.bend index 685863e55..181aee1ee 100644 --- a/tests/golden_tests/run_file/unscoped_never_used.bend +++ b/tests/golden_tests/run_file/unscoped_never_used.bend @@ -1,3 +1,4 @@ +type Bool = True | False main = @x match x { Bool/True : @$x * Bool/False : @x * diff --git a/tests/snapshots/desugar_file__ask_branch.bend.snap b/tests/snapshots/desugar_file__ask_branch.bend.snap index 13735593e..e0f687e89 100644 --- a/tests/snapshots/desugar_file__ask_branch.bend.snap +++ b/tests/snapshots/desugar_file__ask_branch.bend.snap @@ -17,12 +17,6 @@ undefer: (((a -> a) -> b) -> b) unchecked main: Any (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 @@ -35,6 +29,18 @@ 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/True/tag: u24 +(Bool/True/tag) = 0 + +Bool/True: Bool +(Bool/True) = λa (a Bool/True/tag) + +Bool/False/tag: u24 +(Bool/False/tag) = 1 + +Bool/False: Bool +(Bool/False) = λa (a Bool/False/tag) + IO/bind__C0: _ (IO/bind__C0) = λ* λa λb (undefer b a) diff --git a/tests/snapshots/encode_pattern_match__definition_merge.bend.snap b/tests/snapshots/encode_pattern_match__definition_merge.bend.snap index 2a753e7fb..2856468d5 100644 --- a/tests/snapshots/encode_pattern_match__definition_merge.bend.snap +++ b/tests/snapshots/encode_pattern_match__definition_merge.bend.snap @@ -6,6 +6,12 @@ Scott unchecked Foo: Any (Foo) = λa (a λb (b λc (c λf (f 1 1) λg (g 2 2)) λh (h λk (k 1 1) λl (l 2 2))) λm (m λn (n λq (q 3 3) λr (r 3 3)) λs (s λv (v 3 3) λw (w 3 3)))) +Bool/True: Bool +(Bool/True) = λa λ* a + +Bool/False: Bool +(Bool/False) = λ* λb b + Either/Left: (Any -> Either) (Either/Left) = λa λb λ* (b a) @@ -16,6 +22,18 @@ 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; }); }); }); }) +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) + Either/Left/tag: _ (Either/Left/tag) = 0 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 90e833ca3..216ffdf9b 100644 --- a/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap +++ b/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap @@ -30,6 +30,12 @@ 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 + NumScott unchecked If: Any (If) = λa (a λb switch b { 0: λc λd let * = d; c; _: λ* λg λh let * = g; h; }) @@ -63,3 +69,15 @@ 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) diff --git a/tests/snapshots/parse_file__imp_program.bend.snap b/tests/snapshots/parse_file__imp_program.bend.snap index fd25f4d8e..94f1a6470 100644 --- a/tests/snapshots/parse_file__imp_program.bend.snap +++ b/tests/snapshots/parse_file__imp_program.bend.snap @@ -103,3 +103,15 @@ 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)