Skip to content

Commit

Permalink
Updates builtin type Map so that it stores Maybes in its nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
In-Veritas committed Dec 9, 2024
1 parent dbfec9f commit 8f67636
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/example_fun.bend
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/parallel_and.bend
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
8 changes: 1 addition & 7 deletions src/fun/builtins.bend
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions tests/golden_tests/compile_file_o_all/list_merge_sort.bend
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Bool = True | False
Bool.and Bool/True Bool/True = Bool/True
Bool.and Bool/False Bool/False = Bool/False

Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/desugar_file/ask_branch.bend
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Bool = True | False
def main:
with IO:
match _ = Bool/True:
Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/encode_pattern_match/and3.bend
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Bool = True | False

And (Bool/True, Bool/True, Bool/True) = Bool/True
And * = Bool/False
Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/encode_pattern_match/bool_tup.bend
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Bool = True | False
foo (Bool/True, x) = x
foo * = Bool/False

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Bool = True | False
type Either = (Left value) | (Right value)

Foo (Either/Left Bool/False) (Either/Left Bool/False) = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/mutual_recursion/odd_even.bend
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Bool = True | False
(if_ 0 then else) = else
(if_ _ then else) = then

Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/parse_file/imp_program.bend
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Point:
Point { x, y }
type Bool = True | False


def symbols():
Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/run_file/example.bend
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/golden_tests/run_file/filter_bool_id.bend
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type Bool = True | False

def filter(f, ls):
match ls:
case List/Nil:
Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/run_file/mixed_syntax.bend
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type MyTree = (node ~lft ~rgt) | (leaf val)
type Bool = True | False

def tree_xor(tree):
fold tree:
Expand Down
1 change: 1 addition & 0 deletions tests/golden_tests/run_file/unscoped_never_used.bend
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Bool = True | False
main = @x match x {
Bool/True : @$x *
Bool/False : @x *
Expand Down
18 changes: 12 additions & 6 deletions tests/snapshots/desugar_file__ask_branch.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
18 changes: 18 additions & 0 deletions tests/snapshots/encode_pattern_match__definition_merge.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
18 changes: 18 additions & 0 deletions tests/snapshots/encode_pattern_match__list_merge_sort.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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; })
Expand Down Expand Up @@ -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)
12 changes: 12 additions & 0 deletions tests/snapshots/parse_file__imp_program.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8f67636

Please sign in to comment.