mirror of
https://github.com/anoma/juvix.git
synced 2024-12-14 08:27:03 +03:00
3fbc9c7c55
Closes #1644 #1635
85 lines
1.5 KiB
Plaintext
85 lines
1.5 KiB
Plaintext
module Input;
|
|
|
|
open import Data.IO;
|
|
open import Data.String;
|
|
|
|
axiom Int : Type;
|
|
compile Int {
|
|
c ↦ "int";
|
|
};
|
|
|
|
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";
|
|
};
|
|
|
|
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;
|
|
|
|
type 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 := Int_0;
|
|
nat-to-int (suc n) := plus Int_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 Int_1 Int_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;
|