From 8d9a7e0951a635539fe6d105e16faf15807d47f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20V=C3=A9rit=C3=A9?= Date: Fri, 20 Dec 2024 18:47:32 +0100 Subject: [PATCH] Partially updates doc and follows requests from PR review --- docs/builtins.md | 27 +++++- examples/parallel_and.bend | 6 +- src/fun/builtins.bend | 43 ++++----- tests/golden_tests.rs | 2 +- .../mismatched_ask_statements.bend | 2 +- .../compile_file_o_all/list_merge_sort.bend | 3 +- .../non_exhaustive_and.bend | 7 +- .../golden_tests/desugar_file/ask_branch.bend | 11 ++- .../encode_pattern_match/and3.bend | 8 +- .../encode_pattern_match/bool_tup.bend | 9 +- .../encode_pattern_match/common.bend | 2 + .../definition_merge.bend | 2 +- .../encode_pattern_match/list_merge_sort.bend | 2 +- .../encode_pattern_match/var_only.bend | 2 + .../mutual_recursion/odd_even.bend | 1 + .../golden_tests/parse_file/imp_program.bend | 5 +- .../prelude/applies_function_to_map.bend | 13 +++ .../prelude/get_values_from_map.bend | 9 ++ tests/golden_tests/prelude/lists_to_map.bend | 14 +++ .../prelude/map_checked_test.bend | 4 +- .../prelude/map_contains_test.bend | 4 +- tests/golden_tests/prelude/map_tests.bend | 93 ------------------- .../prelude/set_node_when_empty.bend | 12 +++ .../golden_tests/run_file/filter_bool_id.bend | 10 +- tests/golden_tests/run_file/mixed_syntax.bend | 5 +- tests/golden_tests/run_file/unbound_wrap.bend | 2 +- .../run_file/unscoped_never_used.bend | 7 +- ...e_file_o_all__non_exhaustive_and.bend.snap | 2 +- .../desugar_file__ask_branch.bend.snap | 18 ++-- .../desugar_file__mapper_syntax.bend.snap | 2 +- .../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 | 36 +++---- .../encode_pattern_match__full_map.bend.snap | 4 +- ...e_pattern_match__list_merge_sort.bend.snap | 36 +++---- .../encode_pattern_match__var_only.bend.snap | 18 ++++ tests/snapshots/parse_file__imp_map.bend.snap | 6 +- .../parse_file__imp_program.bend.snap | 6 +- ...prelude__applies_function_to_map.bend.snap | 6 ++ .../prelude__get_values_from_map.bend.snap | 6 ++ .../snapshots/prelude__lists_to_map.bend.snap | 6 ++ .../prelude__map_checked_test.bend.snap | 2 +- .../prelude__map_contains_test.bend.snap | 2 +- tests/snapshots/prelude__map_tests.bend.snap | 10 +- .../prelude__set_node_when_empty.bend.snap | 6 ++ .../run_file__filter_bool_id.bend.snap | 4 +- .../run_file__nested_map_get.bend.snap | 4 +- .../run_file__nested_map_set.bend.snap | 4 +- 49 files changed, 316 insertions(+), 249 deletions(-) create mode 100644 tests/golden_tests/prelude/applies_function_to_map.bend create mode 100644 tests/golden_tests/prelude/get_values_from_map.bend create mode 100644 tests/golden_tests/prelude/lists_to_map.bend delete mode 100644 tests/golden_tests/prelude/map_tests.bend create mode 100644 tests/golden_tests/prelude/set_node_when_empty.bend create mode 100644 tests/snapshots/prelude__applies_function_to_map.bend.snap create mode 100644 tests/snapshots/prelude__get_values_from_map.bend.snap create mode 100644 tests/snapshots/prelude__lists_to_map.bend.snap create mode 100644 tests/snapshots/prelude__set_node_when_empty.bend.snap diff --git a/docs/builtins.md b/docs/builtins.md index fc4733411..122d98730 100644 --- a/docs/builtins.md +++ b/docs/builtins.md @@ -161,7 +161,32 @@ tree = ![![!1, !2],![!3, !4]] ``` Technically your trees don't need to end with leaves, but if you don't, your program will be very hard to reason about. +## Maybe +```python +type Maybe(T): + Some{ value } + None +``` +**`Maybe`** is a structure that may or not contain a value. It is meant to be used as a return type for functions that can fail. This way you don't need to resort to unreachable() in order to handle errors. + +#### Syntax +Here's how you create a new `Maybe` containing the Nat value of 1: +```python +maybe = Maybe/Some(Nat/Succ(Nat/Zero)) +``` +## Maybe functions + +### Maybe/unwrap +Maybe has a builtin function that returns the value inside the `Maybe` if it is `Some`, and returns `unreachable()` if it is `None`. +```python +def Maybe/unwrap(m: Maybe(T)) -> T: + match m: + case Maybe/Some: + return m.val + case Maybe/None: + return unreachable() +``` ## Map ```python @@ -173,7 +198,7 @@ type Map: **`Map`** represents a tree with values stored in the branches. It is meant to be used as an efficient map data structure with integer keys and O(log n) read and write operations. -- **Node { value ~left ~right }**: Represents a map node with a `value` and `left` and `right` subtrees. Empty nodes have `*` stored in the `value` field. +- **Node { value ~left ~right }**: Represents a map node with a `Maybe` and `left` and `right` subtrees. Empty nodes have `Maybe/None` stored in the `value` field, whislt non-empty nodes have `Maybe/Some` stored in the `value` field. - **Leaf**: Represents an unwritten, empty portion of the map. #### Syntax diff --git a/examples/parallel_and.bend b/examples/parallel_and.bend index 1860d6e31..bd41552da 100644 --- a/examples/parallel_and.bend +++ b/examples/parallel_and.bend @@ -1,6 +1,8 @@ -type Bool = True | False - # 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 9096c8fb5..1057308d6 100644 --- a/src/fun/builtins.bend +++ b/src/fun/builtins.bend @@ -173,21 +173,21 @@ def Tree/reverse(tree: Tree(T)) -> Tree(T): # MAYBE Impl type Maybe(T): - Some{val: T} + Some { value: T } None # Removes the value on a Maybe def Maybe/unwrap(m: Maybe(T)) -> T: match m: case Maybe/Some: - return m.val + return m.value case Maybe/None: return unreachable() # MAP Impl type Map(T): - Node {value: Maybe(T), ~left: Map(T), ~right: Map(T)} + Node { value: Maybe(T), ~left: Map(T), ~right: Map(T)} Leaf # Creates an empty Map @@ -197,6 +197,8 @@ def Map/empty() -> Map(T): # Gets a value on a Map def Map/get (map: Map(T), key: u24) -> (T, Map(T)): match map: + case Map/Leaf: + return (unreachable(), map) case Map/Node: if (0 == key): return (Maybe/unwrap(map.value), map) @@ -205,24 +207,23 @@ def Map/get (map: Map(T), key: u24) -> (T, Map(T)): return(got, Map/Node(map.value, rest, map.right)) else: (got, rest) = Map/get(map.right, (key / 2)) - return(got, Map/Node(map.value, rest, map.left)) - case Map/Leaf: - return (unreachable(), map) + return(got, Map/Node(map.value, map.left, rest)) + # Checks if a node has a value on a given key, returning Maybe/Some if it does, Maybe/None otherwise -def Map/get_check (map: Map(T), key: u24) -> (Map(T), Maybe(T)): +def Map/get_check (map: Map(T), key: u24) -> (Maybe(T), Map(T)): match map: case Map/Leaf: - return (map, Maybe/None) + return (Maybe/None, map) case Map/Node: if (0 == key): - return (map, map.value) + return (map.value, map) elif (key % 2 == 0): - (new_map, new_value) = Map/get_check(map.left, (key / 2)) - return (Map/Node(map.value, new_map, map.right), new_value) + (new_value, new_map) = Map/get_check(map.left, (key / 2)) + return (new_value, Map/Node(map.value, new_map, map.right)) else: - (new_map, new_value) = Map/get_check(map.right, (key / 2)) - return (Map/Node(map.value, map.left, new_map), new_value) + (new_value, new_map) = Map/get_check(map.right, (key / 2)) + return (new_value, Map/Node(map.value, map.left, new_map)) # Sets a value on a Map def Map/set (map: Map(T), key: u24, value: T) -> Map(T): @@ -244,23 +245,23 @@ def Map/set (map: Map(T), key: u24, value: T) -> Map(T): # Checks if a Map contains a given key -def Map/contains (map: Map(T), key: u24) -> (Map(T), u24): +def Map/contains (map: Map(T), key: u24) -> (u24, Map(T)): match map: case Map/Leaf: - return (map, 0) + return (0, map) case Map/Node: if (0 == key): match map.value: case Maybe/Some: - return (map, 1) + return (1, map) case Maybe/None: - return (map, 0) + return (0, map) elif ((key % 2) == 0): - (new_map, new_value) = Map/contains(map.left, (key / 2)) - return (Map/Node(map.value, new_map, map.right), new_value) + (new_value, new_map) = Map/contains(map.left, (key / 2)) + return (new_value, Map/Node(map.value, new_map, map.right)) else: - (new_map, new_value) = Map/contains(map.right, (key / 2)) - return (Map/Node(map.value, map.left, new_map), new_value) + (new_value, new_map) = Map/contains(map.right, (key / 2)) + return (new_value, Map/Node(map.value, map.left, new_map)) # Applies a funtion to a value on a Map def Map/map (map: Map(T), key: u24, f: T -> T) -> Map(T): diff --git a/tests/golden_tests.rs b/tests/golden_tests.rs index f15bda416..316f32698 100644 --- a/tests/golden_tests.rs +++ b/tests/golden_tests.rs @@ -478,7 +478,7 @@ fn prelude() { let _guard = RUN_MUTEX.lock().unwrap(); let book = parse_book_single_file(code, path)?; let compile_opts = CompileOpts::default(); - let diagnostics_cfg = DiagnosticsConfig::default(); + let diagnostics_cfg = DiagnosticsConfig::new(Severity::Error, true); let (term, _, diags) = run_book(book, RunOpts::default(), compile_opts, diagnostics_cfg, None, "run-c")?.unwrap(); let res = format!("{diags}{term}"); diff --git a/tests/golden_tests/compile_file/mismatched_ask_statements.bend b/tests/golden_tests/compile_file/mismatched_ask_statements.bend index 952c4dda8..ba41a78ff 100644 --- a/tests/golden_tests/compile_file/mismatched_ask_statements.bend +++ b/tests/golden_tests/compile_file/mismatched_ask_statements.bend @@ -9,4 +9,4 @@ def main: x <- wrap(0) case Bool/F: x = wrap(0) - return wrap(x) \ No newline at end of file + 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 26f9fdb43..a11946b93 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,6 +1,5 @@ -type List_ = (Cons head tail) | Nil - type Bool = True | False +type List_ = (Cons head tail) | Nil 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 accebf157..fe6b4fe92 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,5 +1,6 @@ -type Bool = True | False -Bool.and Bool/True Bool/True = Bool/True -Bool.and Bool/False Bool/False = Bool/False +type Bool = T | F + +Bool.and Bool/T Bool/T = Bool/T +Bool.and Bool/F Bool/F = Bool/F Main = * diff --git a/tests/golden_tests/desugar_file/ask_branch.bend b/tests/golden_tests/desugar_file/ask_branch.bend index 667061fbe..ce8fcbe89 100644 --- a/tests/golden_tests/desugar_file/ask_branch.bend +++ b/tests/golden_tests/desugar_file/ask_branch.bend @@ -1,9 +1,12 @@ -type Bool = True | False +type Bool: + T + F + def main: with IO: - match _ = Bool/True: - case Bool/True: + match _ = Bool/T: + case Bool/T: x <- wrap(0) - case Bool/False: + case Bool/F: 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 b7ab81a26..670e709eb 100644 --- a/tests/golden_tests/encode_pattern_match/and3.bend +++ b/tests/golden_tests/encode_pattern_match/and3.bend @@ -1,6 +1,6 @@ -type Bool = True | False +type Bool = T | F -And (Bool/True, Bool/True, Bool/True) = Bool/True -And * = Bool/False +And (Bool/T, Bool/T, Bool/T) = Bool/T +And * = Bool/F -main = (And (Bool/False, Bool/True, Bool/False)) +main = (And (Bool/F, Bool/T, Bool/F)) diff --git a/tests/golden_tests/encode_pattern_match/bool_tup.bend b/tests/golden_tests/encode_pattern_match/bool_tup.bend index bdf8dae15..efc7af9c8 100644 --- a/tests/golden_tests/encode_pattern_match/bool_tup.bend +++ b/tests/golden_tests/encode_pattern_match/bool_tup.bend @@ -1,5 +1,6 @@ -type Bool = True | False -foo (Bool/True, x) = x -foo * = Bool/False +type Bool = T | F -main = (foo (Bool/False, Bool/True)) +foo (Bool/T, x) = x +foo * = Bool/F + +main = (foo (Bool/F, Bool/T)) diff --git a/tests/golden_tests/encode_pattern_match/common.bend b/tests/golden_tests/encode_pattern_match/common.bend index 082497187..4667e42cf 100644 --- a/tests/golden_tests/encode_pattern_match/common.bend +++ b/tests/golden_tests/encode_pattern_match/common.bend @@ -14,6 +14,8 @@ 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 51e6ed7db..052cfe252 100644 --- a/tests/golden_tests/encode_pattern_match/definition_merge.bend +++ b/tests/golden_tests/encode_pattern_match/definition_merge.bend @@ -1,5 +1,5 @@ -type Bool = True | False 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 c1e13e363..6507e6616 100644 --- a/tests/golden_tests/encode_pattern_match/list_merge_sort.bend +++ b/tests/golden_tests/encode_pattern_match/list_merge_sort.bend @@ -1,5 +1,5 @@ -type List_ = (Cons head tail) | Nil type Bool = True | False +type List_ = (Cons head tail) | Nil If Bool/True then else = then If Bool/False then else = else diff --git a/tests/golden_tests/encode_pattern_match/var_only.bend b/tests/golden_tests/encode_pattern_match/var_only.bend index b1d742a9a..5876a4d15 100644 --- a/tests/golden_tests/encode_pattern_match/var_only.bend +++ b/tests/golden_tests/encode_pattern_match/var_only.bend @@ -1,3 +1,5 @@ +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 c40d278a1..612e01f55 100644 --- a/tests/golden_tests/mutual_recursion/odd_even.bend +++ b/tests/golden_tests/mutual_recursion/odd_even.bend @@ -1,4 +1,5 @@ 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 e56648956..7c3ea9e14 100644 --- a/tests/golden_tests/parse_file/imp_program.bend +++ b/tests/golden_tests/parse_file/imp_program.bend @@ -1,6 +1,9 @@ type Point: Point { x, y } -type Bool = True | False + +type Bool: + True + False def symbols(): diff --git a/tests/golden_tests/prelude/applies_function_to_map.bend b/tests/golden_tests/prelude/applies_function_to_map.bend new file mode 100644 index 000000000..547555884 --- /dev/null +++ b/tests/golden_tests/prelude/applies_function_to_map.bend @@ -0,0 +1,13 @@ +# Checks if a generic map contains a given key, and if it does, applies a function to the value, otherwise it returns the map +def test(m: Map(u24), key: u24) -> Map(u24): + def addtwo (x: u24) -> u24: + return (x + 2) + (num, map) = Map/contains(m, key) + if (num == 0): + return m + else: + return Map/map(m, key, addtwo()) + +def main() -> _: + m = {3: 255} + return test(m, 3) diff --git a/tests/golden_tests/prelude/get_values_from_map.bend b/tests/golden_tests/prelude/get_values_from_map.bend new file mode 100644 index 000000000..8f44d9e6d --- /dev/null +++ b/tests/golden_tests/prelude/get_values_from_map.bend @@ -0,0 +1,9 @@ +def test1() -> (u24, Map(u24)): + m = {} + m = Map/set(Map/set(Map/set(Map/empty, 3, 4), 2, 3), 1, 2) + (val, map) = Map/get(m, 1) + return Map/get(map, val) + + +def main() -> _: + return test1() diff --git a/tests/golden_tests/prelude/lists_to_map.bend b/tests/golden_tests/prelude/lists_to_map.bend new file mode 100644 index 000000000..b050b03a7 --- /dev/null +++ b/tests/golden_tests/prelude/lists_to_map.bend @@ -0,0 +1,14 @@ +# Takes two lists and uses one as keys and the other as values, returning a map +def test(m: Map(T), xs: List(u24), ys: List(T)) -> Map(T): + match xs: + case List/Nil: + return Map/Leaf + case List/Cons: + match ys: + case List/Nil: + return Map/Leaf + case List/Cons: + return test(Map/set(m, xs.head, ys.head), xs.tail, ys.tail) + +def main() -> _: + return test(Map/Leaf, List/Cons(1, List/Nil), List/Cons(2, List/Nil)) diff --git a/tests/golden_tests/prelude/map_checked_test.bend b/tests/golden_tests/prelude/map_checked_test.bend index 2597b17f7..68849353c 100644 --- a/tests/golden_tests/prelude/map_checked_test.bend +++ b/tests/golden_tests/prelude/map_checked_test.bend @@ -1,4 +1,4 @@ - -def main(): +def main() -> _: m1 = {0: 42, 1: 7, 2: 13, 3: 255, 4: 100} return Map/get_check(m1, 3) + diff --git a/tests/golden_tests/prelude/map_contains_test.bend b/tests/golden_tests/prelude/map_contains_test.bend index 2fc4d91cd..6c2c227e7 100644 --- a/tests/golden_tests/prelude/map_contains_test.bend +++ b/tests/golden_tests/prelude/map_contains_test.bend @@ -1,3 +1,3 @@ -def main(): +def main() -> _: m1 = {0: 42, 1: 7, 2: 13, 3: 255, 4: 100} - return Map/contains(m1, 3) \ No newline at end of file + return Map/contains(m1, 3) diff --git a/tests/golden_tests/prelude/map_tests.bend b/tests/golden_tests/prelude/map_tests.bend deleted file mode 100644 index b21dc5e6e..000000000 --- a/tests/golden_tests/prelude/map_tests.bend +++ /dev/null @@ -1,93 +0,0 @@ -#This test aims to see if every builtin Map function behaves correctly and returns the expected result - -type Bool: - True - False - -# Returns values from a map -def test1() -> (u24, u24): - m = {1: 1, 2: 2, 3: 3} - return (m[1], m[2]) - -# Takes two lists and uses one as keys and the other as values, returning a map -def test2(m: Map(T), xs: List(u24), ys: List(T)) -> Map(T): - match xs: - case List/Nil: - return Map/Leaf - case List/Cons: - match ys: - case List/Nil: - return Map/Leaf - case List/Cons: - return test2(Map/set(m, xs.head, ys.head), xs.tail, ys.tail) - -# Sets a value if the given node is empty, otherwise returns the map -def test3(m: Map(T), x: u24, v: T) -> Map(T): - (map, val) = Map/get_check(m, x) - match val: - case Maybe/Some: - return m - case Maybe/None: - return Map/set(m, x, v) - -# Checks if a map contains a given key, and if it does, returns the assigned to the key, otherwise it returns the given value -def test4(m: Map(T), x: u24, v: T) -> T: - match Map/contains(m, x): - case 1: - (value, map) = Map/get(m, x) - return value - case 0: - return v - -#Checks if a generic map contains a given key, and if it does, applies a function to the value, otherwise it returns the map -def test5(m: Map(T), key: u24) -> Map(T): - def self (x: T) -> T: - return x - match Map/contains(m, key): - case 1: - return Map/map(m, key, self()) - case 0: - return m - -#Checks if a u24 map contains a given key, and if it does, applies a function to the value, otherwise it returns the map -def test6(m: Map(u24), key: u24) -> Map(u24): - def addtwo (x: u24) -> u24: - return (x + 2) - match Map/contains(m, key): - case 1: - return Map/map(m, key, addtwo()) - case 0: - return m - - -def main(): - m1 = {0: 42, 1: 7, 2: 13, 3: 255, 4: 100} # all u24 numbers - m2 = {0: Bool/True, 1: Bool/False, 2: Bool/True, 3: Bool/False, 4: Bool/True} # booleans - m3 = {0: Nat/Zero, - 1: Nat/Succ(Nat/Zero), - 2: Nat/Succ(Nat/Succ(Nat/Zero)), - 3: Nat/Succ(Nat/Succ(Nat/Succ(Nat/Zero)))} # natural numbers - m4 = {0: 42, - 1: Bool/True, - 2: Nat/Succ(Nat/Zero), - 3: 255, - 4: Bool/False, - 5: Nat/Zero} # mixed types - - m5 = {7: 100, - 3: 42, - 11: 255, - 2: 13, - 5: 77, - 9: 144} # unordered keys with u24 values - - m6 = {0: 1, - 5: 25, - 2: 9, - 8: 64, - 1: 4, - 3: 16, - 7: 49, - 4: 36} # square numbers as values - - return (test1(), test2(Map/Leaf, List/Cons(1, List/Nil), List/Cons(2, List/Nil)), test3(m1, 2, 42), test4(m2, 1, Bool/True), test5(m3, 0), test6(m4, 4), test5(m5, 7), test6(m6, 8)) diff --git a/tests/golden_tests/prelude/set_node_when_empty.bend b/tests/golden_tests/prelude/set_node_when_empty.bend new file mode 100644 index 000000000..bb9124282 --- /dev/null +++ b/tests/golden_tests/prelude/set_node_when_empty.bend @@ -0,0 +1,12 @@ +# Sets a value if the given node is empty, otherwise returns the map +def test(m: Map(T), x: u24, v: T) -> Map(T): + (val, map) = Map/get_check(m, x) + match val: + case Maybe/Some: + return m + case Maybe/None: + return Map/set(m, x, v) + +def main() -> _: + m = {0: 42, 1:23} + return test(m, 3, 4) diff --git a/tests/golden_tests/run_file/filter_bool_id.bend b/tests/golden_tests/run_file/filter_bool_id.bend index 1b554bfb8..f8d49cd40 100644 --- a/tests/golden_tests/run_file/filter_bool_id.bend +++ b/tests/golden_tests/run_file/filter_bool_id.bend @@ -1,4 +1,6 @@ -type Bool = True | False +type Bool: + T + F def filter(f, ls): match ls: @@ -6,10 +8,10 @@ def filter(f, ls): return List/Nil case List/Cons: match f(ls.head): - case Bool/True: + case Bool/T: return List/Cons(ls.head, filter(f, ls.tail)) - case Bool/False: + case Bool/F: return filter(f, ls.tail) def main: - return filter(lambda x: x, [Bool/True]) + return filter(lambda x: x, [Bool/T]) diff --git a/tests/golden_tests/run_file/mixed_syntax.bend b/tests/golden_tests/run_file/mixed_syntax.bend index 20d37256b..766d3bed9 100644 --- a/tests/golden_tests/run_file/mixed_syntax.bend +++ b/tests/golden_tests/run_file/mixed_syntax.bend @@ -1,5 +1,8 @@ +type Bool: + True + False + 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/unbound_wrap.bend b/tests/golden_tests/run_file/unbound_wrap.bend index cf8178fae..c168abd02 100644 --- a/tests/golden_tests/run_file/unbound_wrap.bend +++ b/tests/golden_tests/run_file/unbound_wrap.bend @@ -2,7 +2,7 @@ type Maybe_ = (Some x) | None Maybe_/bind val nxt = match val { Maybe_/Some: (nxt val.x) - Maybe_/None: Maybe/None + Maybe_/None: Maybe_/None } main = with Maybe_ { diff --git a/tests/golden_tests/run_file/unscoped_never_used.bend b/tests/golden_tests/run_file/unscoped_never_used.bend index 181aee1ee..07edaa7a2 100644 --- a/tests/golden_tests/run_file/unscoped_never_used.bend +++ b/tests/golden_tests/run_file/unscoped_never_used.bend @@ -1,5 +1,6 @@ -type Bool = True | False +type Bool = T | F + main = @x match x { - Bool/True : @$x * - Bool/False : @x * + Bool/T : @$x * + Bool/F : @x * } 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 b5509c980..d75690cbd 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/False' of type 'Bool' not covered + Non-exhaustive pattern matching rule. Constructor 'Bool/F' 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 e0f687e89..27e80ee09 100644 --- a/tests/snapshots/desugar_file__ask_branch.bend.snap +++ b/tests/snapshots/desugar_file__ask_branch.bend.snap @@ -15,7 +15,7 @@ undefer: (((a -> a) -> b) -> b) (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)) +(main) = (IO/bind (Bool/T λa switch a { 0: (IO/wrap 0); _: λ* (IO/wrap 0); }) λb (b λc λd (c d) IO/wrap)) IO/Done/tag: u24 (IO/Done/tag) = 0 @@ -29,17 +29,17 @@ 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/T/tag: u24 +(Bool/T/tag) = 0 -Bool/True: Bool -(Bool/True) = λa (a Bool/True/tag) +Bool/T: Bool +(Bool/T) = λa (a Bool/T/tag) -Bool/False/tag: u24 -(Bool/False/tag) = 1 +Bool/F/tag: u24 +(Bool/F/tag) = 1 -Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) +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 8bb2bc6f0..6f1aae231 100644 --- a/tests/snapshots/desugar_file__mapper_syntax.bend.snap +++ b/tests/snapshots/desugar_file__mapper_syntax.bend.snap @@ -48,7 +48,7 @@ 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 d (/ a 2)); (e, (Map/Node b f c)) +(Map/get__C0) = λa λb λc λd let (e, f) = (Map/get d (/ a 2)); (e, (Map/Node b c f)) Map/get__C1: _ (Map/get__C1) = λ* λa λb λc λd let (e, f) = (Map/get c (/ a 2)); (e, (Map/Node b f d)) diff --git a/tests/snapshots/encode_pattern_match__and3.bend.snap b/tests/snapshots/encode_pattern_match__and3.bend.snap index 952a20279..1b6a84c82 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/True Bool/False) λ* Bool/False f) λ* λ* Bool/False c d) +(And) = λa let (b, c, d) = a; (b λe λf (e λg (g Bool/T Bool/F) λ* Bool/F f) λ* λ* Bool/F c d) unchecked main: Any -(main) = (And (Bool/False, Bool/True, Bool/False)) +(main) = (And (Bool/F, Bool/T, Bool/F)) -Bool/True: Bool -(Bool/True) = λa λ* a +Bool/T: Bool +(Bool/T) = λa λ* a -Bool/False: Bool -(Bool/False) = λ* λb b +Bool/F: Bool +(Bool/F) = λ* λ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/True; _: λ* Bool/False; }); _: λ* λ* Bool/False; } g); _: λ* λ* λ* Bool/False; } 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/T; _: λ* Bool/F; }); _: λ* λ* Bool/F; } g); _: λ* λ* λ* Bool/F; } c d) unchecked main: Any -(main) = (And (Bool/False, Bool/True, Bool/False)) +(main) = (And (Bool/F, Bool/T, Bool/F)) -Bool/True/tag: _ -(Bool/True/tag) = 0 +Bool/T/tag: _ +(Bool/T/tag) = 0 -Bool/True: Bool -(Bool/True) = λa (a Bool/True/tag) +Bool/T: Bool +(Bool/T) = λa (a Bool/T/tag) -Bool/False/tag: _ -(Bool/False/tag) = 1 +Bool/F/tag: _ +(Bool/F/tag) = 1 -Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) +Bool/F: Bool +(Bool/F) = λa (a Bool/F/tag) diff --git a/tests/snapshots/encode_pattern_match__bool_tup.bend.snap b/tests/snapshots/encode_pattern_match__bool_tup.bend.snap index c6274d188..ae4e71b54 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/False c) +(foo) = λa let (b, c) = a; (b λd d λ* Bool/F c) unchecked main: Any -(main) = (foo (Bool/False, Bool/True)) +(main) = (foo (Bool/F, Bool/T)) -Bool/True: Bool -(Bool/True) = λa λ* a +Bool/T: Bool +(Bool/T) = λa λ* a -Bool/False: Bool -(Bool/False) = λ* λb b +Bool/F: Bool +(Bool/F) = λ* λb b NumScott unchecked foo: Any -(foo) = λa let (b, c) = a; (b λd switch d { 0: λe e; _: λ* λ* Bool/False; } c) +(foo) = λa let (b, c) = a; (b λd switch d { 0: λe e; _: λ* λ* Bool/F; } c) unchecked main: Any -(main) = (foo (Bool/False, Bool/True)) +(main) = (foo (Bool/F, Bool/T)) -Bool/True/tag: _ -(Bool/True/tag) = 0 +Bool/T/tag: _ +(Bool/T/tag) = 0 -Bool/True: Bool -(Bool/True) = λa (a Bool/True/tag) +Bool/T: Bool +(Bool/T) = λa (a Bool/T/tag) -Bool/False/tag: _ -(Bool/False/tag) = 1 +Bool/F/tag: _ +(Bool/F/tag) = 1 -Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) +Bool/F: Bool +(Bool/F) = λa (a Bool/F/tag) diff --git a/tests/snapshots/encode_pattern_match__common.bend.snap b/tests/snapshots/encode_pattern_match__common.bend.snap index d01e03d16..8ba0880f0 100644 --- a/tests/snapshots/encode_pattern_match__common.bend.snap +++ b/tests/snapshots/encode_pattern_match__common.bend.snap @@ -27,6 +27,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 + Light/Red: Light (Light/Red) = λa λ* λ* a @@ -97,6 +103,18 @@ 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 2856468d5..ba5305920 100644 --- a/tests/snapshots/encode_pattern_match__definition_merge.bend.snap +++ b/tests/snapshots/encode_pattern_match__definition_merge.bend.snap @@ -6,33 +6,21 @@ 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) Either/Right: (Any -> Either) (Either/Right) = λa λ* λc (c a) -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/True) = λa λ* a Bool/False: Bool -(Bool/False) = λa (a Bool/False/tag) +(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; }); }); }); }) Either/Left/tag: _ (Either/Left/tag) = 0 @@ -45,3 +33,15 @@ 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 741188aef..d59dc0af5 100644 --- a/tests/snapshots/encode_pattern_match__full_map.bend.snap +++ b/tests/snapshots/encode_pattern_match__full_map.bend.snap @@ -7,7 +7,7 @@ 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) { 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)) +(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 c g)); _: λ* 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) = * @@ -41,7 +41,7 @@ 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) { 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); }) +(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 d h)); _: λ* 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) = * 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 216ffdf9b..d1e56e142 100644 --- a/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap +++ b/tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap @@ -24,18 +24,18 @@ 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) -List_/Cons: (Any -> Any -> List_) -(List_/Cons) = λa λb λc λ* (c a b) - -List_/Nil: List_ -(List_/Nil) = λ* λb b - 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) + +List_/Nil: List_ +(List_/Nil) = λ* λb b + NumScott unchecked If: Any (If) = λa (a λb switch b { 0: λc λd let * = d; c; _: λ* λg λh let * = g; h; }) @@ -58,18 +58,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) -List_/Cons/tag: _ -(List_/Cons/tag) = 0 - -List_/Cons: (Any -> Any -> List_) -(List_/Cons) = λa λb λc (c List_/Cons/tag a b) - -List_/Nil/tag: _ -(List_/Nil/tag) = 1 - -List_/Nil: List_ -(List_/Nil) = λa (a List_/Nil/tag) - Bool/True/tag: _ (Bool/True/tag) = 0 @@ -81,3 +69,15 @@ Bool/False/tag: _ Bool/False: Bool (Bool/False) = λa (a Bool/False/tag) + +List_/Cons/tag: _ +(List_/Cons/tag) = 0 + +List_/Cons: (Any -> Any -> List_) +(List_/Cons) = λa λb λc (c List_/Cons/tag a b) + +List_/Nil/tag: _ +(List_/Nil/tag) = 1 + +List_/Nil: List_ +(List_/Nil) = λa (a List_/Nil/tag) diff --git a/tests/snapshots/encode_pattern_match__var_only.bend.snap b/tests/snapshots/encode_pattern_match__var_only.bend.snap index 01e50e07b..9780a609b 100644 --- a/tests/snapshots/encode_pattern_match__var_only.bend.snap +++ b/tests/snapshots/encode_pattern_match__var_only.bend.snap @@ -9,9 +9,27 @@ 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 385269bc1..95ae3c240 100644 --- a/tests/snapshots/parse_file__imp_map.bend.snap +++ b/tests/snapshots/parse_file__imp_map.bend.snap @@ -3,13 +3,13 @@ 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; } +(Maybe/unwrap m) = match m = m { Maybe/Some: m.value; 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/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/get map key) = match map = map { Map/Leaf: (unreachable, 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 map.left rest)); _ %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/set: ((Map T) -> u24 -> T -> (Map T)) (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); }; } @@ -24,7 +24,7 @@ Maybe/Some/tag: _ (Maybe/Some/tag) = 0 Maybe/Some: (T -> (Maybe T)) -(Maybe/Some) = λval λ%x (%x Maybe/Some/tag val) +(Maybe/Some) = λvalue λ%x (%x Maybe/Some/tag value) Maybe/None/tag: _ (Maybe/None/tag) = 1 diff --git a/tests/snapshots/parse_file__imp_program.bend.snap b/tests/snapshots/parse_file__imp_program.bend.snap index 94f1a6470..2570cafa8 100644 --- a/tests/snapshots/parse_file__imp_program.bend.snap +++ b/tests/snapshots/parse_file__imp_program.bend.snap @@ -3,13 +3,13 @@ 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; } +(Maybe/unwrap m) = match m = m { Maybe/Some: m.value; 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/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/get map key) = match map = map { Map/Leaf: (unreachable, 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 map.left rest)); _ %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/set: ((Map T) -> u24 -> T -> (Map T)) (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); }; } @@ -78,7 +78,7 @@ Maybe/Some/tag: _ (Maybe/Some/tag) = 0 Maybe/Some: (T -> (Maybe T)) -(Maybe/Some) = λval λ%x (%x Maybe/Some/tag val) +(Maybe/Some) = λvalue λ%x (%x Maybe/Some/tag value) Maybe/None/tag: _ (Maybe/None/tag) = 1 diff --git a/tests/snapshots/prelude__applies_function_to_map.bend.snap b/tests/snapshots/prelude__applies_function_to_map.bend.snap new file mode 100644 index 000000000..a279ced92 --- /dev/null +++ b/tests/snapshots/prelude__applies_function_to_map.bend.snap @@ -0,0 +1,6 @@ +--- +source: tests/golden_tests.rs +input_file: tests/golden_tests/prelude/applies_function_to_map.bend +--- +Strict mode: +λa (a Map/Node/tag Maybe/None Map/Leaf λb (b Map/Node/tag Maybe/None Map/Leaf λc (c Map/Node/tag λd (d Maybe/Some/tag 257) Map/Leaf Map/Leaf))) diff --git a/tests/snapshots/prelude__get_values_from_map.bend.snap b/tests/snapshots/prelude__get_values_from_map.bend.snap new file mode 100644 index 000000000..166d42797 --- /dev/null +++ b/tests/snapshots/prelude__get_values_from_map.bend.snap @@ -0,0 +1,6 @@ +--- +source: tests/golden_tests.rs +input_file: tests/golden_tests/prelude/get_values_from_map.bend +--- +Strict mode: +(3, λa (a Map/Node/tag Maybe/None λb (b Map/Node/tag Maybe/None Map/Leaf λc (c Map/Node/tag λd (d Maybe/Some/tag 3) Map/Leaf Map/Leaf)) λe (e Map/Node/tag λf (f Maybe/Some/tag 2) Map/Leaf λg (g Map/Node/tag λh (h Maybe/Some/tag 4) Map/Leaf Map/Leaf)))) diff --git a/tests/snapshots/prelude__lists_to_map.bend.snap b/tests/snapshots/prelude__lists_to_map.bend.snap new file mode 100644 index 000000000..62ddbf89b --- /dev/null +++ b/tests/snapshots/prelude__lists_to_map.bend.snap @@ -0,0 +1,6 @@ +--- +source: tests/golden_tests.rs +input_file: tests/golden_tests/prelude/lists_to_map.bend +--- +Strict mode: +Map/Leaf diff --git a/tests/snapshots/prelude__map_checked_test.bend.snap b/tests/snapshots/prelude__map_checked_test.bend.snap index d3c7999ad..654f3fc99 100644 --- a/tests/snapshots/prelude__map_checked_test.bend.snap +++ b/tests/snapshots/prelude__map_checked_test.bend.snap @@ -3,4 +3,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/prelude/map_checked_test.bend --- Strict mode: -(λa (a Map/Node/tag λb (b Maybe/Some/tag 42) λc (c Map/Node/tag Maybe/None λd (d Map/Node/tag Maybe/None Map/Leaf λe (e Map/Node/tag λf (f Maybe/Some/tag 100) Map/Leaf Map/Leaf)) λg (g Map/Node/tag λh (h Maybe/Some/tag 13) Map/Leaf Map/Leaf)) λi (i Map/Node/tag λj (j Maybe/Some/tag 7) Map/Leaf λk (k Map/Node/tag λl (l Maybe/Some/tag 255) Map/Leaf Map/Leaf))), λm (m Maybe/Some/tag 255)) +(λa (a Maybe/Some/tag 255), λb (b Map/Node/tag λc (c Maybe/Some/tag 42) λd (d Map/Node/tag Maybe/None λe (e Map/Node/tag Maybe/None Map/Leaf λf (f Map/Node/tag λg (g Maybe/Some/tag 100) Map/Leaf Map/Leaf)) λh (h Map/Node/tag λi (i Maybe/Some/tag 13) Map/Leaf Map/Leaf)) λj (j Map/Node/tag λk (k Maybe/Some/tag 7) Map/Leaf λl (l Map/Node/tag λm (m Maybe/Some/tag 255) Map/Leaf Map/Leaf)))) diff --git a/tests/snapshots/prelude__map_contains_test.bend.snap b/tests/snapshots/prelude__map_contains_test.bend.snap index ffd612e0d..acaf09272 100644 --- a/tests/snapshots/prelude__map_contains_test.bend.snap +++ b/tests/snapshots/prelude__map_contains_test.bend.snap @@ -3,4 +3,4 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/prelude/map_contains_test.bend --- Strict mode: -(λa (a Map/Node/tag λb (b Maybe/Some/tag 42) λc (c Map/Node/tag Maybe/None λd (d Map/Node/tag Maybe/None Map/Leaf λe (e Map/Node/tag λf (f Maybe/Some/tag 100) Map/Leaf Map/Leaf)) λg (g Map/Node/tag λh (h Maybe/Some/tag 13) Map/Leaf Map/Leaf)) λi (i Map/Node/tag λj (j Maybe/Some/tag 7) Map/Leaf λk (k Map/Node/tag λl (l Maybe/Some/tag 255) Map/Leaf Map/Leaf))), 1) +(1, λa (a Map/Node/tag λb (b Maybe/Some/tag 42) λc (c Map/Node/tag Maybe/None λd (d Map/Node/tag Maybe/None Map/Leaf λe (e Map/Node/tag λf (f Maybe/Some/tag 100) Map/Leaf Map/Leaf)) λg (g Map/Node/tag λh (h Maybe/Some/tag 13) Map/Leaf Map/Leaf)) λi (i Map/Node/tag λj (j Maybe/Some/tag 7) Map/Leaf λk (k Map/Node/tag λl (l Maybe/Some/tag 255) Map/Leaf Map/Leaf)))) diff --git a/tests/snapshots/prelude__map_tests.bend.snap b/tests/snapshots/prelude__map_tests.bend.snap index ae6552f04..0dc16f14d 100644 --- a/tests/snapshots/prelude__map_tests.bend.snap +++ b/tests/snapshots/prelude__map_tests.bend.snap @@ -2,5 +2,11 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/prelude/map_tests.bend --- -Strict mode: -((1, 3), (Map/Leaf, (λa (a Map/Node/tag λb (b Maybe/Some/tag 42) λc (c Map/Node/tag Maybe/None λd (d Map/Node/tag Maybe/None Map/Leaf λe (e Map/Node/tag λf (f Maybe/Some/tag 100) Map/Leaf Map/Leaf)) λg (g Map/Node/tag λh (h Maybe/Some/tag 13) Map/Leaf Map/Leaf)) λi (i Map/Node/tag λj (j Maybe/Some/tag 7) Map/Leaf λk (k Map/Node/tag λl (l Maybe/Some/tag 255) Map/Leaf Map/Leaf))), (Bool/False, (λm (m Map/Node/tag λn (n Maybe/Some/tag Nat/Zero) λo (o Map/Node/tag Maybe/None Map/Leaf λp (p Map/Node/tag λq (q Maybe/Some/tag λr (r Nat/Succ/tag λs (s Nat/Succ/tag Nat/Zero))) Map/Leaf Map/Leaf)) λt (t Map/Node/tag λu (u Maybe/Some/tag λv (v Nat/Succ/tag Nat/Zero)) Map/Leaf λw (w Map/Node/tag λx (x Maybe/Some/tag λy (y Nat/Succ/tag λz (z Nat/Succ/tag λab (ab Nat/Succ/tag Nat/Zero)))) Map/Leaf Map/Leaf))), (λbb (bb Map/Node/tag λcb (cb Maybe/Some/tag 42) λdb (db Map/Node/tag Maybe/None λeb (eb Map/Node/tag Maybe/None Map/Leaf λfb (fb Map/Node/tag λgb (gb Maybe/Some/tag λhb (hb 3)) Map/Leaf Map/Leaf)) λib (ib Map/Node/tag λjb (jb Maybe/Some/tag λkb (kb Nat/Succ/tag Nat/Zero)) Map/Leaf Map/Leaf)) λlb (lb Map/Node/tag λmb (mb Maybe/Some/tag Bool/True) λnb (nb Map/Node/tag Maybe/None Map/Leaf λob (ob Map/Node/tag λpb (pb Maybe/Some/tag Nat/Zero) Map/Leaf Map/Leaf)) λqb (qb Map/Node/tag λrb (rb Maybe/Some/tag 255) Map/Leaf Map/Leaf))), (λsb (sb Map/Node/tag Maybe/None λtb (tb Map/Node/tag Maybe/None Map/Leaf λub (ub Map/Node/tag λvb (vb Maybe/Some/tag 13) Map/Leaf Map/Leaf)) λwb (wb Map/Node/tag Maybe/None λxb (xb Map/Node/tag Maybe/None λyb (yb Map/Node/tag Maybe/None Map/Leaf λzb (zb Map/Node/tag λac (ac Maybe/Some/tag 144) Map/Leaf Map/Leaf)) λbc (bc Map/Node/tag λcc (cc Maybe/Some/tag 77) Map/Leaf Map/Leaf)) λdc (dc Map/Node/tag λec (ec Maybe/Some/tag 42) λfc (fc Map/Node/tag Maybe/None Map/Leaf λgc (gc Map/Node/tag λhc (hc Maybe/Some/tag 255) Map/Leaf Map/Leaf)) λic (ic Map/Node/tag λjc (jc Maybe/Some/tag 100) Map/Leaf Map/Leaf)))), λkc (kc Map/Node/tag λlc (lc Maybe/Some/tag 1) λmc (mc Map/Node/tag Maybe/None λnc (nc Map/Node/tag Maybe/None λoc (oc Map/Node/tag Maybe/None Map/Leaf λpc (pc Map/Node/tag λqc (qc Maybe/Some/tag 66) Map/Leaf Map/Leaf)) λrc (rc Map/Node/tag λsc (sc Maybe/Some/tag 36) Map/Leaf Map/Leaf)) λtc (tc Map/Node/tag λuc (uc Maybe/Some/tag 9) Map/Leaf Map/Leaf)) λvc (vc Map/Node/tag λwc (wc Maybe/Some/tag 4) λxc (xc Map/Node/tag Maybe/None Map/Leaf λyc (yc Map/Node/tag λzc (zc Maybe/Some/tag 25) Map/Leaf Map/Leaf)) λad (ad Map/Node/tag λbd (bd Maybe/Some/tag 16) Map/Leaf λcd (cd Map/Node/tag λdd (dd Maybe/Some/tag 49) Map/Leaf Map/Leaf))))))))))) +Errors: +In tests/golden_tests/prelude/map_tests.bend : +- expected: case 0 +- detected: + 36 | case 1: + 37 |  (value, map) = Map/get(m, x) + 38 |  return value + 39 |  case 0: diff --git a/tests/snapshots/prelude__set_node_when_empty.bend.snap b/tests/snapshots/prelude__set_node_when_empty.bend.snap new file mode 100644 index 000000000..1d335f7fe --- /dev/null +++ b/tests/snapshots/prelude__set_node_when_empty.bend.snap @@ -0,0 +1,6 @@ +--- +source: tests/golden_tests.rs +input_file: tests/golden_tests/prelude/set_node_when_empty.bend +--- +Strict mode: +λa (a Map/Node/tag λb (b Maybe/Some/tag 42) Map/Leaf λc (c Map/Node/tag λd (d Maybe/Some/tag 23) Map/Leaf λe (e Map/Node/tag λf (f Maybe/Some/tag 4) Map/Leaf Map/Leaf))) diff --git a/tests/snapshots/run_file__filter_bool_id.bend.snap b/tests/snapshots/run_file__filter_bool_id.bend.snap index 8b995e9c2..760ed391e 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/True] +[Bool/T] Scott: -[Bool/True] +[Bool/T] diff --git a/tests/snapshots/run_file__nested_map_get.bend.snap b/tests/snapshots/run_file__nested_map_get.bend.snap index 77a296892..51bd56561 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: -84 +43 Scott: -84 +43 diff --git a/tests/snapshots/run_file__nested_map_set.bend.snap b/tests/snapshots/run_file__nested_map_set.bend.snap index 5b069d9f7..ea6941a0c 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