2022-06-13 15:04:38 +03:00
|
|
|
module Input;
|
|
|
|
|
2022-06-28 11:25:43 +03:00
|
|
|
open import Data.IO;
|
|
|
|
open import Data.String;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
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;
|