1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-11 08:25:46 +03:00
juvix/tests/negative/Termination/Data/QuickSort.juvix
Jonathan Cubides 3b3ea45da9
Rename MiniJuvix to Juvix (#259)
* Renaming MiniJuvix to Juvix

* Make Ormolu happy

* Make Hlint happy

* Remove redundant imports

* Fix shell tests and add target ci to our Makefile

* Make pre-commit happy
2022-07-08 13:59:45 +02:00

39 lines
1.1 KiB
Plaintext

module Data.QuickSort;
import Data.Bool;
open Data.Bool;
import Data.Nat;
open Data.Nat;
inductive List (A : Type) {
nil : List A;
cons : A → List A → List A;
};
filter : (A : Type) → (A → Bool) → List A → List A;
filter A f nil ≔ nil A;
filter A f (cons h hs) ≔ ite (List A) (f h)
(cons A h (filter A f hs))
(filter A f hs);
concat : (A : Type) → List A → List A → List A;
concat A nil ys ≔ ys;
concat A (cons x xs) ys ≔ cons A x (concat A xs ys);
ltx : (A : Type) → (A → A → Bool) → A → A → Bool;
ltx A lessThan x y ≔ lessThan y x;
gex : (A : Type) → (A → A → Bool) → A → A → Bool;
gex A lessThan x y ≔ not (ltx A lessThan x y) ;
quicksort : (A : Type) → (A → A → Bool) → List A → List A;
quicksort A _ nil ≔ nil A;
quicksort A _ (cons x nil) ≔ cons A x (nil A);
quicksort A lessThan (cons x ys) ≔
concat A (quicksort A lessThan (filter A (ltx A lessThan x) ys))
(concat A
(cons A x (nil A))
(quicksort A lessThan (filter A (gex A lessThan x)) ys));
end;