mirror of
https://github.com/anoma/juvix.git
synced 2024-12-15 18:13:56 +03:00
803d2008d9
* remove ≔ from the language and replace it by := * revert accidental changes in juvix input mode * update stdlib submodule * rename ℕ by Nat in the tests and examples * fix shell tests
35 lines
663 B
Plaintext
35 lines
663 B
Plaintext
module Data.Nat;
|
|
|
|
open import Data.String;
|
|
open import Data.Int;
|
|
|
|
inductive Nat {
|
|
zero : Nat;
|
|
suc : Nat → Nat;
|
|
};
|
|
|
|
foreign c {
|
|
void* natInd(int n, void* zeroCtor, juvix_function_t* sucCtor) {
|
|
if (n <= 0) return zeroCtor;
|
|
return ((void* (*) (juvix_function_t*, void*))sucCtor->fun)(sucCtor, natInd(n - 1, zeroCtor, sucCtor));
|
|
\}
|
|
};
|
|
|
|
axiom natInd : Int → Nat → (Nat → Nat) → Nat;
|
|
|
|
compile natInd {
|
|
c ↦ "natInd";
|
|
};
|
|
|
|
natToInt : Nat → Int;
|
|
natToInt zero := Int_0;
|
|
natToInt (suc n) := Int_1 + (natToInt n);
|
|
|
|
natToStr : Nat → String;
|
|
natToStr n := intToStr (natToInt n);
|
|
|
|
intToNat : Int → Nat;
|
|
intToNat x := natInd x zero suc;
|
|
|
|
end;
|