aboutsummaryrefslogtreecommitdiff
path: root/examples/guess-number.ts
diff options
context:
space:
mode:
Diffstat (limited to 'examples/guess-number.ts')
-rw-r--r--examples/guess-number.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/examples/guess-number.ts b/examples/guess-number.ts
new file mode 100644
index 0000000..aca3915
--- /dev/null
+++ b/examples/guess-number.ts
@@ -0,0 +1,15 @@
+import { Print, PutString, Bind, Kind1, JsExpr, ReadLine, Seq } from '../src/stdlib'
+
+export type main = Bind<
+ JsExpr<"Math.floor(Math.random() * 10)">,
+ StartGuessing
+>
+
+interface AskForGuess<N extends number> extends Kind1<string> {
+ return: this['input'] extends `${N}` ? Print<"Yaya"> : Print<"naaah">
+}
+
+interface StartGuessing extends Kind1<number> {
+ return: Bind<Seq<[PutString<"Your guess? ">, ReadLine]>, AskForGuess<this['input']>>
+}
+