diff --git a/examples/example_fun.bend b/examples/example_fun.bend index 4e1b7356..dbac0765 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 2dcd9cdd..1860d6e3 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 3495616b..253c9ce4 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 9528ff9b..26f9fdb4 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 c897858e..accebf15 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 98f5871c..667061fb 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 b6f465f0..b7ab81a2 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 9136cfb7..bdf8dae1 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 c63c0aac..51e6ed7d 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 dcf3d389..c1e13e36 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 600b085a..c40d278a 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 f9bf6727..e5664895 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 92a1124a..fe374cd6 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 ba2e6b3c..1b554bfb 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 6b47e8b5..20d37256 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 685863e5..181aee1e 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 13735593..e0f687e8 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 2a753e7f..2856468d 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 90e833ca..216ffdf9 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 fd25f4d8..94f1a647 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)