Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/In-Veritas/Bend in order to…
Browse files Browse the repository at this point in the history
… catch up to current commit
  • Loading branch information
In-Veritas committed Dec 9, 2024
2 parents 0ad7503 + f97fa76 commit dbfec9f
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 177 deletions.
1 change: 0 additions & 1 deletion examples/example_fun.bend
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions examples/parallel_and.bend
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 5 additions & 0 deletions src/fun/builtins.bend
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 3 additions & 7 deletions tests/golden_tests/compile_file/mismatched_ask_statements.bend
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion tests/golden_tests/compile_file_o_all/list_merge_sort.bend
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
type Bool = True | False
type List_ = (Cons head tail) | Nil

If Bool/True then else = then
Expand Down
6 changes: 2 additions & 4 deletions tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend
Original file line number Diff line number Diff line change
@@ -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 = *
10 changes: 3 additions & 7 deletions tests/golden_tests/desugar_file/ask_branch.bend
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 3 additions & 4 deletions tests/golden_tests/encode_pattern_match/and3.bend
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 3 additions & 5 deletions tests/golden_tests/encode_pattern_match/bool_tup.bend
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 0 additions & 2 deletions tests/golden_tests/encode_pattern_match/common.bend
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ type List_
= (Cons x xs)
| Nil

type Bool = True | False

type Light = Red | Yellow | Green

type Direction
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
type Bool = True | False
type List_ = (Cons head tail) | Nil

If Bool/True then else = then
Expand Down
2 changes: 0 additions & 2 deletions tests/golden_tests/encode_pattern_match/var_only.bend
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
type Bool = False | True

(Foo a b) = λf (f a)
(Foo a b) = b

Expand Down
2 changes: 0 additions & 2 deletions tests/golden_tests/mutual_recursion/odd_even.bend
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
type Bool = True | False

(if_ 0 then else) = else
(if_ _ then else) = then

Expand Down
1 change: 0 additions & 1 deletion tests/golden_tests/run_file/example.bend
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions tests/golden_tests/run_file/filter_bool_id.bend
Original file line number Diff line number Diff line change
@@ -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])
4 changes: 0 additions & 4 deletions tests/golden_tests/run_file/mixed_syntax.bend
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
type Bool:
True
False

type MyTree = (node ~lft ~rgt) | (leaf val)

def tree_xor(tree):
Expand Down
6 changes: 2 additions & 4 deletions tests/golden_tests/run_file/unscoped_never_used.bend
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
type Bool = T | F

main = @x match x {
Bool/T : @$x *
Bool/F : @x *
Bool/True : @$x *
Bool/False : @x *
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 7 additions & 13 deletions tests/snapshots/desugar_file__ask_branch.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

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

Expand Down Expand Up @@ -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

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

0 comments on commit dbfec9f

Please sign in to comment.