Idris-dev/test/basic002/test006.idr
Jan de Muijnck-Hughes 5ea6aa0520 Address semantic differences in putting things to STDOUT.
The changes are as follows:

+ `print` is for putting showable things to STDOUT.
+ `printLn` is for putting showable things to STDOUT with a new line
+ `putCharLn` for putting a single character to STDOUT, with a new line.

Effects has been updated accordingly.
2015-03-06 17:26:33 +00:00

39 lines
858 B
Idris

module Main
data Parity : Nat -> Type where
even : {n : Nat} -> Parity (n + n)
odd : {n : Nat} -> Parity (S (n + n))
parity : (n:Nat) -> Parity n
parity Z = even {n=Z}
parity (S Z) = odd {n=Z}
parity (S (S k)) with (parity k)
parity (S (S (j + j))) | (even {n = j}) ?= even {n=S j}
parity (S (S (S (j + j)))) | (odd {n = j}) ?= odd {n=S j}
natToBin : Nat -> List Bool
natToBin Z = Nil
natToBin k with (parity k)
natToBin (j + j) | even {n = j} = False :: natToBin j
natToBin (S (j + j)) | odd {n = j} = True :: natToBin j
main : IO ()
main = do printLn (natToBin 42)
---------- Proofs ----------
Main.parity_lemma_2 = proof {
intro;
intro;
rewrite sym (plusSuccRightSucc j j);
trivial;
};
Main.parity_lemma_1 = proof {
intro j;
intro;
rewrite sym (plusSuccRightSucc j j);
trivial;
};