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";
|
|
|
|
};
|
|
|
|
|
2022-08-12 18:31:15 +03:00
|
|
|
axiom Int_0 : Int;
|
|
|
|
compile Int_0 {
|
|
|
|
c ↦ "0";
|
|
|
|
};
|
|
|
|
|
|
|
|
axiom Int_1 : Int;
|
|
|
|
compile Int_1 {
|
|
|
|
c ↦ "1";
|
|
|
|
};
|
|
|
|
|
|
|
|
axiom Int_2 : Int;
|
|
|
|
compile Int_2 {
|
|
|
|
c ↦ "2";
|
|
|
|
};
|
|
|
|
|
2022-06-13 15:04:38 +03:00
|
|
|
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;
|
2022-09-30 03:55:32 +03:00
|
|
|
apply f a b := f a b;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
2023-01-03 15:49:04 +03:00
|
|
|
type Nat :=
|
|
|
|
zero : Nat
|
|
|
|
| suc : Nat → Nat;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
plus-nat : Nat → Nat → Nat;
|
2022-09-30 03:55:32 +03:00
|
|
|
plus-nat zero n := n;
|
|
|
|
plus-nat (suc m) n := suc (plus-nat m n);
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
apply-nat : (Nat → Nat) → Nat → Nat;
|
2022-09-30 03:55:32 +03:00
|
|
|
apply-nat f a := f a;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
apply-nat2 : (Nat → Nat → Nat) → Nat → Nat → Nat;
|
2022-09-30 03:55:32 +03:00
|
|
|
apply-nat2 f a b := f a b;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
nat-to-int : Nat → Int;
|
2022-09-30 03:55:32 +03:00
|
|
|
nat-to-int zero := Int_0;
|
|
|
|
nat-to-int (suc n) := plus Int_1 (nat-to-int n);
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
one : Nat;
|
2022-09-30 03:55:32 +03:00
|
|
|
one := suc zero;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
nest-apply : ((Nat → Nat) → Nat → Nat) → (Nat → Nat) → Nat → Nat;
|
2022-09-30 03:55:32 +03:00
|
|
|
nest-apply f g x := f g x;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
two : Nat;
|
2022-09-30 03:55:32 +03:00
|
|
|
two := suc one;
|
2022-06-13 15:04:38 +03:00
|
|
|
|
|
|
|
main : Action;
|
2022-09-30 03:55:32 +03:00
|
|
|
main := put-str "plus 1 2: "
|
2022-08-12 18:31:15 +03:00
|
|
|
>> put-str-ln (to-str (apply plus Int_1 Int_2))
|
2022-06-13 15:04:38 +03:00
|
|
|
>> 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;
|