1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-14 17:32:00 +03:00
juvix/tests/positive/MiniC/ClosureNoEnv/Input.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

72 lines
1.4 KiB
Plaintext

module Input;
open import Data.IO;
open import Data.String;
axiom Int : Type;
compile Int {
c ↦ "int";
};
axiom to-str : Int → String;
compile to-str {
c ↦ "intToStr";
};
foreign c {
int cplus(int l, int r) {
return l + r;
\}
};
axiom plus : Int → Int → Int;
compile plus {
c ↦ "cplus";
};
apply : (Int → Int → Int) → Int → Int → Int;
apply f a b ≔ f a b;
inductive Nat {
zero : Nat;
suc : Nat → Nat;
};
plus-nat : Nat → Nat → Nat;
plus-nat zero n ≔ n;
plus-nat (suc m) n ≔ suc (plus-nat m n);
apply-nat : (Nat → Nat) → Nat → Nat;
apply-nat f a ≔ f a;
apply-nat2 : (Nat → Nat → Nat) → Nat → Nat → Nat;
apply-nat2 f a b ≔ f a b;
nat-to-int : Nat → Int;
nat-to-int zero ≔ 0;
nat-to-int (suc n) ≔ plus 1 (nat-to-int n);
one : Nat;
one ≔ suc zero;
nest-apply : ((Nat → Nat) → Nat → Nat) → (Nat → Nat) → Nat → Nat;
nest-apply f g x ≔ f g x;
two : Nat;
two ≔ suc one;
main : Action;
main ≔ put-str "plus 1 2: "
>> put-str-ln (to-str (apply plus 1 2))
>> put-str "suc one: "
>> put-str-ln (to-str (nat-to-int (apply-nat suc one)))
>> put-str "plus-nat 1 2: "
>> put-str-ln (to-str (nat-to-int (apply-nat2 plus-nat one two)))
>> put-str "nest-apply apply-nat suc one: "
>> put-str-ln (to-str (nat-to-int (nest-apply apply-nat suc one)));
end;