2022-06-01 18:54:53 +03:00
|
|
|
module Input;
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Booleans
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inductive Bool {
|
|
|
|
true : Bool;
|
|
|
|
false : Bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Strings
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
axiom String : Type;
|
|
|
|
|
|
|
|
compile String {
|
|
|
|
ghc ↦ "[Char]";
|
|
|
|
c ↦ "char*";
|
|
|
|
};
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- IO
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
axiom Action : Type;
|
|
|
|
|
|
|
|
compile Action {
|
|
|
|
ghc ↦ "IO ()";
|
|
|
|
c ↦ "int";
|
|
|
|
};
|
|
|
|
|
|
|
|
foreign c {
|
|
|
|
int sequence(int a, int b) {
|
|
|
|
return a + b;
|
|
|
|
\}
|
|
|
|
};
|
|
|
|
|
|
|
|
infixl 1 >>;
|
|
|
|
axiom >> : Action → Action → Action;
|
|
|
|
|
|
|
|
compile >> {
|
|
|
|
ghc ↦ "(>>)";
|
|
|
|
c ↦ "sequence";
|
|
|
|
};
|
|
|
|
|
|
|
|
axiom put-str : String → Action;
|
|
|
|
|
|
|
|
compile put-str {
|
|
|
|
ghc ↦ "putStr";
|
|
|
|
c ↦ "putStr";
|
|
|
|
};
|
|
|
|
|
|
|
|
axiom put-str-ln : String → Action;
|
|
|
|
|
|
|
|
compile put-str-ln {
|
|
|
|
ghc ↦ "putStrLn";
|
|
|
|
c ↦ "putStrLn";
|
|
|
|
};
|
|
|
|
|
|
|
|
bool-to-str : Bool → String;
|
|
|
|
bool-to-str true ≔ "True";
|
|
|
|
bool-to-str false ≔ "False";
|
|
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Pair
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
inductive Pair (A : Type) (B : Type) {
|
|
|
|
mkPair : A → B → Pair A B;
|
|
|
|
};
|
|
|
|
|
2022-06-13 15:25:22 +03:00
|
|
|
fst : {A : Type} → {B : Type} → Pair A B → A;
|
|
|
|
fst (mkPair a b) ≔ a;
|
2022-06-01 18:54:53 +03:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- Main
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
fst-of-pair : Action;
|
|
|
|
fst-of-pair ≔ (put-str "fst (True, False) = ")
|
2022-06-13 15:25:22 +03:00
|
|
|
>> put-str-ln (bool-to-str (fst (mkPair true false)));
|
2022-06-01 18:54:53 +03:00
|
|
|
|
|
|
|
main : Action;
|
|
|
|
main ≔ fst-of-pair;
|
|
|
|
|
|
|
|
end;
|