Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Update for compatibility with the ASCII stdlib #14

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ContainersPrelude.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ContainersPrelude;

import Juvix.Builtin.V1 open public;
import Stdlib.Data.String.Base open public;
import Stdlib.Data.Product open public;
import Stdlib.Data.Pair open public;
import Stdlib.Data.List.Base open public;
import Stdlib.System.IO.Base open public;
import Stdlib.System.IO.String open public;
Expand Down
8 changes: 4 additions & 4 deletions Data/Map.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ key {A B} : Binding A B -> A
value {A B} : Binding A B -> B
| (binding _ b) := b;

toPair {A B} : Binding A B -> A × B
toPair {A B} : Binding A B -> Pair A B
| (binding a b) := a, b;

instance
Expand Down Expand Up @@ -49,14 +49,14 @@ lookup {A B} {{Ord A}} (k : A) : Map A B -> Maybe B

{-# specialize: [1, f] #-}
fromListWith {A B} {{Ord A}} (f : B -> B -> B) (xs : List
(A × B)) : Map A B :=
(Pair A B)) : Map A B :=
for (acc := empty) (k, v in xs)
insertWith f k v acc;

fromList {A B} {{Ord A}} : List (A × B) -> Map A B :=
fromList {A B} {{Ord A}} : List (Pair A B) -> Map A B :=
fromListWith λ {old new := new};

toList {A B} : Map A B -> List (A × B)
toList {A B} : Map A B -> List (Pair A B)
| (mkMap s) := map (x in Set.toList s) toPair x;

size {A B} : Map A B -> Nat
Expand Down
4 changes: 2 additions & 2 deletions Data/Queue/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ check {A} : Queue A -> Queue A

--- 𝒪(n) worst-case, but 𝒪(1) amortized. Returns the first element and the
-- rest of the ;Queue;. If the ;Queue; is empty then returns ;nothing;.
pop {A} : Queue A -> Maybe (A × Queue A)
pop {A} : Queue A -> Maybe (Pair A (Queue A))
| (queue nil _) := nothing
| (queue (x :: front) back) :=
just (x, check (queue front back));
Expand Down Expand Up @@ -74,7 +74,7 @@ eqQueueI {A} {{Eq A}} : Eq (Queue A) :=

instance
showQueueI {A} {{Show A}} : Show (Queue A) :=
mkShow (Show.show ∘ toList);
mkShow (toList >> Show.show);

instance
ordQueueI {A} {{Ord A}} : Ord (Queue A) :=
Expand Down
6 changes: 3 additions & 3 deletions Data/Set/AVL.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ lookupWith {A K} {{o : Ord K}} (f : A -> K) (x : K)
--- 𝒪(log 𝓃). Queries whether an element is in an ;AVLTree;.
{-# specialize: [1] #-}
member? {A} {{Ord A}} (x : A) : AVLTree A -> Bool :=
isJust ∘ lookupWith id x;
lookupWith id x >> isJust;

--- 𝒪(log 𝓃). Inserts an element into and ;AVLTree; using a function to
--- deduplicate entries.
Expand Down Expand Up @@ -134,7 +134,7 @@ insert {A} {{Ord A}} : A -> AVLTree A -> AVLTree A :=
delete {A} {{o : Ord A}} (x : A) : AVLTree A -> AVLTree A :=
let
{-# specialize-by: [o] #-}
deleteMin : AVLTree A -> Maybe (A × AVLTree A)
deleteMin : AVLTree A -> Maybe (Pair A (AVLTree A))
| empty := nothing
| (node v _ l r) :=
case deleteMin l of {
Expand Down Expand Up @@ -228,7 +228,7 @@ toTree {A} : AVLTree A -> Maybe (Tree A)

--- Returns the textual representation of an ;AVLTree;.
pretty {A} {{Show A}} : AVLTree A -> String :=
maybe "empty" Tree.treeToString ∘ toTree;
toTree >> maybe "empty" Tree.treeToString;

instance
eqAVLTreeI {A} {{Eq A}} : Eq (AVLTree A) :=
Expand Down
3 changes: 2 additions & 1 deletion Data/Tmp.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
module Data.Tmp;

import ContainersPrelude open;
import Stdlib.Trait open;

printNatListLn : List Nat → IO
| nil := printStringLn "nil"
| (x :: xs) :=
printNat x >> printString " :: " >> printNatListLn xs;
printNat x >>> printString " :: " >>> printNatListLn xs;

mapMaybe {A B} (f : A -> B) : Maybe A -> Maybe B
| nothing := nothing
Expand Down
4 changes: 2 additions & 2 deletions Data/Tree.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ drawForest {A} {{Show A}} : Forest A -> List String
"|" :: shift "+- " "| " (draw h) ++ drawForest hs;

treeToString {A} {{Show A}} : Tree A -> String :=
unlines ∘ draw;
draw >> unlines;

forestToString {A} {{Show A}} : Forest A -> String :=
unlines ∘ drawForest;
drawForest >> unlines;
8 changes: 6 additions & 2 deletions Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ import PackageDescription.V2 open;
package : Package :=
defaultPackage
{name := "containers";
version := mkVersion 0 11 0;
dependencies := [github "anoma" "juvix-stdlib" "v0.3.0"]};
version := mkVersion 0 12 0;
dependencies := [ github
"anoma"
"juvix-stdlib"
"v0.4.0"
]};
6 changes: 3 additions & 3 deletions juvix.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file was autogenerated by Juvix version 0.6.1.
# This file was autogenerated by Juvix version 0.6.3.
# Do not edit this file manually.

version: 2
checksum: 75024fc227f6d942045d351ee3d066579e709c363a65d02928019b74a165ab49
checksum: 9915437ae9fa7cc71e22a1cc18517849f7695b04dfd8fecfce0d8ec5285aa9cd
dependencies:
- git:
name: anoma_juvix-stdlib
ref: e2efe4e6fe8e8bf1766050a7fa7ad8ff4e8c69fc
ref: 89a5960fb8a29291e9271986b98ca7b1edf4031b
url: https://github.com/anoma/juvix-stdlib
dependencies: []
6 changes: 5 additions & 1 deletion test/Main.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ import Test.Map open using {suite as mapSuite};
import Test.Queue open using {suite as queueSuite};
import Test.UnbalancedSet open using {suite as unbalancedSetSuite};

main : IO := runTestSuite avlSuite >> runTestSuite mapSuite >> runTestSuite queueSuite >> runTestSuite unbalancedSetSuite;
main : IO :=
runTestSuite avlSuite
>>> runTestSuite mapSuite
>>> runTestSuite queueSuite
>>> runTestSuite unbalancedSetSuite;
4 changes: 2 additions & 2 deletions test/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package : Package :=
defaultPackage
{name := "containers-tests";
main := just "Main.juvix";
dependencies := [ github "anoma" "juvix-stdlib" "v0.3.0"
; github "anoma" "juvix-test" "v0.10.0"
dependencies := [ github "anoma" "juvix-stdlib" "v0.4.0"
; github "anoma" "juvix-test" "v0.11.0"
; path "../"
]};
10 changes: 5 additions & 5 deletions test/Test/AVL.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import Test.JuvixUnit open;
import Juvix.Builtin.V1 open;
import Stdlib.System.IO.Base open;
import Stdlib.System.IO.String open;
import Stdlib.Data.Product open;
import Stdlib.Data.Pair open;
import Stdlib.Data.List.Base open;

import Data.Set.AVL open;

--- Test for size and balance.
mkTests : String × Nat × AVLTree Nat -> List Test
mkTests : Pair String (Pair Nat (AVLTree Nat)) -> List Test
| (title, len, s) :=
let
mkTitle : String -> String
Expand All @@ -25,7 +25,7 @@ mkTests : String × Nat × AVLTree Nat -> List Test
(assertTrue balanceMsg (isBalanced s))
];

TestDescr : Type := String × Nat × AVLTree Nat;
TestDescr : Type := Pair String (Pair Nat (AVLTree Nat));

s1 : TestDescr := "s1", 5, fromList [1; 2; 8; 3; 3; 2; 9];

Expand All @@ -51,5 +51,5 @@ suite : TestSuite := testSuite "AVL Set" tests;

main : IO :=
printStringLn (pretty (snd (snd s1)))
>> printStringLn (prettyDebug (snd (snd s1)))
>> runTestSuite suite;
>>> printStringLn (prettyDebug (snd (snd s1)))
>>> runTestSuite suite;
4 changes: 2 additions & 2 deletions test/Test/Map.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Test.Map;

import Juvix.Builtin.V1 open;
import Stdlib.System.IO.Base open;
import Stdlib.Data.Product open;
import Stdlib.Data.Pair open;
import Stdlib.Data.List open using {quickSort};
import Stdlib.Function open;
import Test.JuvixUnit open;
Expand All @@ -17,7 +17,7 @@ tests : List Test :=
m2 : Map Nat Nat :=
Map.insert 3 4 (Map.insert 1 2 Map.empty);
assertEqListPair
: List (Nat × Nat) -> List (Nat × Nat) -> Assertion
: List (Pair Nat Nat) -> List (Pair Nat Nat) -> Assertion
| actual expected :=
assertEqual
"lists are not equal"
Expand Down
6 changes: 3 additions & 3 deletions test/Test/Queue.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Test.Queue;
import Juvix.Builtin.V1 open;
import Stdlib.System.IO.Base open;
import Stdlib.Function open;
import Stdlib.Data.Product open;
import Stdlib.Data.Pair open;
import Test.JuvixUnit open;

import Data.Queue open;
Expand Down Expand Up @@ -39,7 +39,7 @@ tests : List Test :=
"Queue.fromList composes with toList should be the identity"
(assertEqual
"fromList . toList should be the identity"
(fromList ∘ toList $ q3)
(toList >> fromList <| q3)
q3)
; testCase
"Queue.pop should remove first element"
Expand All @@ -52,7 +52,7 @@ tests : List Test :=
(assertEqual
"tail of queue q3"
(tail q3)
((just ∘ fromList) [2; 3]))
((fromList >> just) [2; 3]))
];

suite : TestSuite := testSuite "Queue" tests;
Expand Down
12 changes: 6 additions & 6 deletions test/juvix.lock.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# This file was autogenerated by Juvix version 0.6.2.
# This file was autogenerated by Juvix version 0.6.3.
# Do not edit this file manually.

version: 2
checksum: 9c537bb8969fcc407cae30fdd701846137d3980db8ef118a2724fd7f490e8c00
checksum: 23c0c8c38f6e1b5351519e97e3aa5f998d3396cd7d67846aaebf78eac94b8dd1
dependencies:
- git:
name: anoma_juvix-stdlib
ref: 73ecbc57738f4bde6f4f39636436ba38504b33f6
ref: 89a5960fb8a29291e9271986b98ca7b1edf4031b
url: https://github.com/anoma/juvix-stdlib
dependencies: []
- git:
name: anoma_juvix-test
ref: 4e54de43de077eb95329202902ba15891c14b068
ref: 4254b60351f283f31868498d4e238af8259243f8
url: https://github.com/anoma/juvix-test
dependencies:
- git:
name: anoma_juvix-stdlib
ref: 73ecbc57738f4bde6f4f39636436ba38504b33f6
ref: 89a5960fb8a29291e9271986b98ca7b1edf4031b
url: https://github.com/anoma/juvix-stdlib
dependencies: []
- path: ../
dependencies:
- git:
name: anoma_juvix-stdlib
ref: e2efe4e6fe8e8bf1766050a7fa7ad8ff4e8c69fc
ref: 00f6f503dbc2cfa72bd469fb8ce7edd0e9730639
url: https://github.com/anoma/juvix-stdlib
dependencies: []
Loading