mirror of
https://github.com/anoma/juvix.git
synced 2025-01-05 22:46:08 +03:00
e2f2d0a2f4
This PR resolves a few bugs in the Makefile targets for formatting and type checking Juvix files, which were preventing the capture of type checking errors for our examples and bad formatting for all the Juvix files in the repository. With this PR, our code should now be clean, and we can expect every file to be properly formatted and type checked. Changes made: - [x] Updated `make format-juvix-files` - [x] Updated `make check-format-juvix-files` - [x] Formatted all Juvix files - [x] Comment a fragment in `examples/milestone/Bank/Bank.juvix` In the future, we will drastically simplify the Makefile once we improve the `format` and the `type check` command for example posted here: - #2066 - #2087 Related: - #2063 - #2040 (due to some typechecking errors we're not capturing before) - #2105 - https://github.com/anoma/juvix/issues/2059
59 lines
1.4 KiB
Plaintext
59 lines
1.4 KiB
Plaintext
module Demo;
|
|
|
|
-- standard library prelude
|
|
import Stdlib.Prelude open;
|
|
-- for comparisons on natural numbers
|
|
import Stdlib.Data.Nat.Ord open;
|
|
-- for Ordering
|
|
|
|
even : Nat → Bool;
|
|
even zero := true;
|
|
even (suc zero) := false;
|
|
even (suc (suc n)) := even n;
|
|
|
|
even' : Nat → Bool;
|
|
even' n := mod n 2 == 0;
|
|
|
|
-- base 2 logarithm rounded down
|
|
terminating
|
|
log2 : Nat → Nat;
|
|
log2 n := if (n <= 1) 0 (suc (log2 (div n 2)));
|
|
|
|
type Tree (A : Type) :=
|
|
| leaf : A → Tree A
|
|
| node : A → Tree A → Tree A → Tree A;
|
|
|
|
mirror : {A : Type} → Tree A → Tree A;
|
|
mirror t@(leaf _) := t;
|
|
mirror (node x l r) := node x (mirror r) (mirror l);
|
|
|
|
tree : Tree Nat;
|
|
tree := node 2 (node 3 (leaf 0) (leaf 1)) (leaf 7);
|
|
|
|
preorder : {A : Type} → Tree A → List A;
|
|
preorder (leaf x) := x :: nil;
|
|
preorder (node x l r) :=
|
|
x :: nil ++ preorder l ++ preorder r;
|
|
|
|
terminating
|
|
sort : {A : Type} → (A → A → Ordering) → List A → List A;
|
|
sort _ nil := nil;
|
|
sort _ xs@(_ :: nil) := xs;
|
|
sort {A} cmp xs :=
|
|
uncurry
|
|
(merge (mkOrd cmp))
|
|
(both (sort cmp) (splitAt (div (length xs) 2) xs));
|
|
|
|
printNatListLn : List Nat → IO;
|
|
printNatListLn nil := printStringLn "nil";
|
|
printNatListLn (x :: xs) :=
|
|
printNat x >> printString " :: " >> printNatListLn xs;
|
|
|
|
main : IO;
|
|
main :=
|
|
printStringLn "Hello!"
|
|
>> printNatListLn (preorder (mirror tree))
|
|
>> printNatListLn (sort compare (preorder (mirror tree)))
|
|
>> printNatLn (log2 3)
|
|
>> printNatLn (log2 130);
|