Skip to content

Commit

Permalink
Add none fixity (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz authored Sep 28, 2023
1 parent 2680b19 commit 50aa583
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Stdlib/Data/Fixity.juvix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Stdlib.Data.Fixity;

syntax fixity none := none;

syntax fixity rapp := binary {assoc := right};
syntax fixity lapp := binary {assoc := left; same := rapp};
syntax fixity seq := binary {assoc := left; above := [lapp]};
Expand Down
10 changes: 6 additions & 4 deletions Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ merge {A} {{Ord A}} : List A → List A → List A
partition {A} (f : A → Bool) : List A → List A × List A
| nil := nil, nil
| (x :: xs) :=
case partition f xs of {l1, l2 :=
if (f x) (x :: l1, l2) (l1, x :: l2)};
case partition f xs of {
l1, l2 := if (f x) (x :: l1, l2) (l1, x :: l2)
};

syntax operator ++ cons;

Expand Down Expand Up @@ -209,8 +210,9 @@ quickSort {A} {{Ord A}} : List A → List A :=
| nil := nil
| xs@(_ :: nil) := xs
| (x :: xs) :=
case partition (isGT ∘ Ord.cmp x) xs of {l1, l2 :=
go l1 ++ x :: go l2};
case partition (isGT ∘ Ord.cmp x) xs of {
l1, l2 := go l1 ++ x :: go l2
};
in go;

--- 𝒪(𝓃) Filters out every ;nothing; from a ;List;.
Expand Down
27 changes: 15 additions & 12 deletions test/Test.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ prop-tailLengthOneLess : List Int -> Bool

prop-splitAtRecombine : Nat -> List Int -> Bool
| n xs :=
case splitAt n xs of {lhs, rhs :=
eqListInt xs (lhs ++ rhs)};
case splitAt n xs of {
lhs, rhs := eqListInt xs (lhs ++ rhs)
};

prop-splitAtLength : Nat -> List Int -> Bool
| n xs :=
case splitAt
n
(xs ++ replicate (sub n (length xs)) (ofNat 0)) of {lhs
, rhs :=
length lhs Nat.== n
&& length rhs Nat.== sub (length xs) n};
case
splitAt n (xs ++ replicate (sub n (length xs)) (ofNat 0))
of {
lhs, rhs :=
length lhs Nat.== n && length rhs Nat.== sub (length xs) n
};
-- Make sure the list has length at least n

prop-mergeSumLengths : List Int -> List Int -> Bool
Expand All @@ -47,10 +48,12 @@ prop-mergeSumLengths : List Int -> List Int -> Bool

prop-partition : List Int -> (Int -> Bool) -> Bool
| xs p :=
case partition p xs of {lhs, rhs :=
all p lhs
&& not (any p rhs)
&& eqListInt (sortInt xs) (sortInt (lhs ++ rhs))};
case partition p xs of {
lhs, rhs :=
all p lhs
&& not (any p rhs)
&& eqListInt (sortInt xs) (sortInt (lhs ++ rhs))
};

prop-distributive : Int -> Int -> (Int -> Int) -> Bool
| a b f := f (a + b) == f a + f b;
Expand Down

0 comments on commit 50aa583

Please sign in to comment.