Skip to content

Commit

Permalink
Improve Set and Map modules in the standard library (#3120)
Browse files Browse the repository at this point in the history
* Updates the standard library to
anoma/juvix-stdlib#130
* Also changes `null` to `isEmpty`, which required updating some tests

---------

Co-authored-by: Paul Cadman <[email protected]>
  • Loading branch information
lukaszcz and paulcadman authored Oct 24, 2024
1 parent e951df0 commit 8f180cc
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/milestone/TicTacToe/Logic/GameState.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ won (state : GameState) : Bool :=
draw (state : GameState) : Bool :=
let
squares := Board.squares (GameState.board state);
in null (possibleMoves (flatten squares));
in isEmpty (possibleMoves (flatten squares));
6 changes: 3 additions & 3 deletions tests/Anoma/Compilation/positive/test007.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ map' {A B} (f : A → B) : List A → List B :=
-- TODO: Restore when anoma backend supports strings
-- terminating
-- map'' {A B} {{Partial}} (f : A → B) (x : List A) : List B :=
-- if (null x) nil (f (phead x) :: map'' f (tail x));
-- if (isEmpty x) nil (f (phead x) :: map'' f (tail x));

lst : List Nat := 0 :: 1 :: nil;

main : List Nat :=
trace (null lst)
>-> trace (null (nil {Nat}))
trace (isEmpty lst)
>-> trace (isEmpty (nil {Nat}))
>-> trace (head 1 lst)
>-> trace (tail lst)
>-> trace (head 0 (tail lst))
Expand Down
4 changes: 2 additions & 2 deletions tests/Casm/Compilation/positive/test007.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ map' {A B} (f : A → B) : List A → List B :=
lst : List Nat := 0 :: 1 :: nil;

main : Nat :=
ite (null lst) 1 0
+ ite (null (nil {Nat})) 1 0
ite (isEmpty lst) 1 0
+ ite (isEmpty (nil {Nat})) 1 0
+ head 1 lst
+ head 0 (tail lst)
+ head 0 (tail (map ((+) 1) lst))
Expand Down
6 changes: 3 additions & 3 deletions tests/Compilation/positive/test007.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ map' {A B} (f : A → B) : List A → List B :=

terminating
map'' {A B} {{Partial}} (f : A → B) (x : List A) : List B :=
ite (null x) nil (f (phead x) :: map'' f (tail x));
ite (isEmpty x) nil (f (phead x) :: map'' f (tail x));

lst : List Nat := 0 :: 1 :: nil;

Expand All @@ -24,8 +24,8 @@ printNatListLn (lst : List Nat) : IO :=
printNatList lst >>> printString "\n";

main : IO :=
printBoolLn (null lst)
>>> printBoolLn (null (nil {Nat}))
printBoolLn (isEmpty lst)
>>> printBoolLn (isEmpty (nil {Nat}))
>>> printNatLn (head 1 lst)
>>> printNatListLn (tail lst)
>>> printNatLn (head 0 (tail lst))
Expand Down
4 changes: 2 additions & 2 deletions tests/Rust/Compilation/positive/test007.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ map' {A B} (f : A → B) : List A → List B :=
lst : List Nat := 0 :: 1 :: nil;

main : Nat :=
ite (null lst) 1 0
+ ite (null (nil {Nat})) 1 0
ite (isEmpty lst) 1 0
+ ite (isEmpty (nil {Nat})) 1 0
+ head 1 lst
+ head 0 (tail lst)
+ head 0 (tail (map ((+) 1) lst))
Expand Down
4 changes: 2 additions & 2 deletions tests/smoke/Commands/dev/repl.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ tests:
Stdlib.Prelude> \1
exit-status: 0

- name: check-type-null
- name: check-type-isEmpty
command:
- juvix
- dev
- repl
stdout:
contains: "{A : Type} -> (list : List A) -> Bool"
stdin: ":type null"
stdin: ":type isEmpty"
exit-status: 0

- name: check-type-suc
Expand Down
4 changes: 2 additions & 2 deletions tests/smoke/Commands/repl.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ tests:
Stdlib.Prelude> \1
exit-status: 0

- name: check-type-null
- name: check-type-isEmpty
command:
- juvix
- repl
stdout:
contains: "{A : Type} -> (list : List A) -> Bool"
stdin: ":type null"
stdin: ":type isEmpty"
exit-status: 0

- name: check-type-suc
Expand Down

0 comments on commit 8f180cc

Please sign in to comment.