aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/custom-effect.ts10
-rw-r--r--examples/ffi.ts12
-rw-r--r--examples/file.ts9
-rw-r--r--examples/greeting.ts14
-rw-r--r--examples/guess-number.ts15
5 files changed, 60 insertions, 0 deletions
diff --git a/examples/custom-effect.ts b/examples/custom-effect.ts
new file mode 100644
index 0000000..948caf4
--- /dev/null
+++ b/examples/custom-effect.ts
@@ -0,0 +1,10 @@
+import { DefineEffect, Effect } from '../src/stdlib'
+
+interface Wow<_A, _B> extends Effect { }
+
+export type main = [
+ DefineEffect<"Wow", `(a, b) => {
+ console.log(typeToString(a), '-->', typeToString(b))
+ }`>,
+ Wow<"a", 69>,
+]
diff --git a/examples/ffi.ts b/examples/ffi.ts
new file mode 100644
index 0000000..7a73a0a
--- /dev/null
+++ b/examples/ffi.ts
@@ -0,0 +1,12 @@
+import { Bind, Debug, JsExpr, Kind1 } from "../src/stdlib"
+
+interface PrintK<Label extends string = ""> extends Kind1 {
+ return: Debug<Label, this['input']>
+}
+
+type Square<N extends number> = JsExpr<`${N} ** 2`>
+
+export type main = [
+ Bind<JsExpr<"{ boobaa: [5 * 3, 5 * 2] }">, PrintK<'|'>>,
+ Bind<Square<69>, PrintK<"69^2 =">>,
+]
diff --git a/examples/file.ts b/examples/file.ts
new file mode 100644
index 0000000..3de26d3
--- /dev/null
+++ b/examples/file.ts
@@ -0,0 +1,9 @@
+import { Bind, Kind1, ReadFile, PutStringLn } from '../src/stdlib'
+
+interface PrintK extends Kind1<string> {
+ return: PutStringLn<this['input']>
+}
+
+export type main = [
+ Bind<ReadFile<"./default.nix">, PrintK>,
+]
diff --git a/examples/greeting.ts b/examples/greeting.ts
new file mode 100644
index 0000000..5e1a164
--- /dev/null
+++ b/examples/greeting.ts
@@ -0,0 +1,14 @@
+import { PutString, Bind, Kind1, ReadLine, Seq } from '../src/stdlib'
+
+interface GreetK extends Kind1<string> {
+ return: Seq<[
+ PutString<"Hello, ">,
+ PutString<`${this['input']}\n`>
+ ]>,
+}
+
+export type main = [
+ PutString<"Your name? ">,
+ Bind<ReadLine, GreetK>,
+]
+
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']>>
+}
+