-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement builtin type Map, and its corresponding functions, as well …
…as the Maybe type
- Loading branch information
1 parent
e195a55
commit f97fa76
Showing
44 changed files
with
177 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
type Bool: | ||
True | ||
False | ||
|
||
# Returns values from a map | ||
def test1() -> (u24, u24): | ||
m = {1: 1, 2: 2, 3: 3} | ||
|
10 changes: 3 additions & 7 deletions
10
tests/golden_tests/compile_file/mismatched_ask_statements.bend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
4 changes: 1 addition & 3 deletions
4
tests/golden_tests/compile_file_o_all/match_adt_non_exhaustive.bend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
type Maybe = (Some val) | None | ||
|
||
main = @maybe | ||
match maybe { | ||
Maybe/None: 0 | ||
Maybe/Some: match maybe.val { | ||
Maybe/Some: match maybe.value { | ||
Maybe/None: 0 | ||
} | ||
} |
6 changes: 2 additions & 4 deletions
6
tests/golden_tests/compile_file_o_all/non_exhaustive_and.bend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
4 changes: 1 addition & 3 deletions
4
tests/golden_tests/encode_pattern_match/match_adt_unscoped_lambda.bend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
type Maybe = None | (Some val) | ||
|
||
main = (match x = (Maybe/Some 1) { | ||
Maybe/None: @$x * | ||
Maybe/Some: x.val | ||
Maybe/Some: x.value | ||
} $x) |
2 changes: 0 additions & 2 deletions
2
tests/golden_tests/encode_pattern_match/match_adt_unscoped_var.bend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
type Maybe = None | (Some val) | ||
|
||
Foo = @$x match x = (Maybe/Some 1) { | ||
Maybe/None: $x | ||
Maybe/Some: x.val | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
type Point: | ||
Point { x, y } | ||
|
||
type Bool: | ||
True | ||
False | ||
|
||
|
||
def symbols(): | ||
x = { `x`: 5, 2: 3 }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
type Maybe = (Some x) | None | ||
|
||
Maybe/bind val nxt = match val { | ||
Maybe/Some: (nxt val.x) | ||
Maybe/None: Maybe/None | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
# We want to make sure that the default value is not mistakenly erased in the first level of flattening. | ||
type Maybe = (Some x) | None | ||
|
||
(DoubleUnwrap (Maybe/Some (Maybe/Some x)) *) = x | ||
(DoubleUnwrap (Maybe/Some (Maybe/Some val)) *) = val | ||
(DoubleUnwrap * x) = x | ||
|
||
Main = (DoubleUnwrap (Maybe/Some Maybe/None) 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.