1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/tests/positive/MiniC/MutuallyRecursive/Data/Nat.juvix

34 lines
657 B
Plaintext

module Data.Nat;
open import Data.String;
open import Data.Int;
type 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;