aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-06 18:07:26 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-06 18:07:26 +0530
commite319818b8cc27450237f4b6b96022458ae478ab2 (patch)
tree2c92f4f4b52ead1b879b8e1411ff782fff3dbe6b /src
parent549440bf01ac5fa76d34d0b263f409a9802121e4 (diff)
downloadts-types-lang-e319818b8cc27450237f4b6b96022458ae478ab2.tar.gz
ts-types-lang-e319818b8cc27450237f4b6b96022458ae478ab2.zip
refactor: splits funcs into stdlib
Diffstat (limited to 'src')
-rw-r--r--src/index.ts42
-rw-r--r--src/runtime.ts4
-rw-r--r--src/stdlib/fs.ts6
-rw-r--r--src/stdlib/index.ts4
-rw-r--r--src/stdlib/io.ts18
-rw-r--r--src/stdlib/stdio.ts10
-rw-r--r--src/stdlib/sys.ts8
7 files changed, 54 insertions, 38 deletions
diff --git a/src/index.ts b/src/index.ts
index aad0c00..7ee4461 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,47 +1,17 @@
-export interface EffectAtom<T = unknown> { output: T }
-export type Effect = EffectAtom[]
-
-export interface PutString<_ extends string> extends EffectAtom { }
-export interface Print<_ extends any> extends EffectAtom { }
-export interface Debug<_ extends string, T> extends EffectAtom<T> { }
-
-export interface WriteFile<_Path extends string, _Content extends string> extends EffectAtom { }
-export interface ReadFile<_Path extends string> extends EffectAtom<string> { }
-
-export interface GetEnv<_Name extends string> extends EffectAtom<string> { }
-export interface GetArgs extends EffectAtom<string[]> { }
-
-export interface ReadLine extends EffectAtom<string> { }
-
-export interface JsExpr<_Expr extends string> extends EffectAtom<any> { }
-
-export interface Program<Effs extends Effect, ExitCode extends number = 0> {
- effects: Effs,
- exitCode: ExitCode,
-}
-
-export interface Kind1<Inp = unknown, Out = unknown> {
- input: Inp
- return: Out
-}
-
-export interface ChainIO<Eff extends EffectAtom, Fn extends Kind1> extends EffectAtom {
- input: Eff
- chainTo: Fn
-}
+import { Program, Print, PutString, Bind, Debug, Kind1, GetEnv, JsExpr, ReadFile, GetArgs, ReadLine } from './stdlib'
interface PrintK<Label extends string = ""> extends Kind1<unknown> {
return: Debug<Label, this['input']>
}
export type main = Program<[
- ChainIO<GetArgs, PrintK>,
+ Bind<GetArgs, PrintK>,
[1, 2, 3] extends infer Res ? Print<Res> : never,
- ChainIO<GetEnv<"NODE_ENV">, PrintK>,
- ChainIO<JsExpr<"{ boobaa: [5 * 3, 5 * 2] }">, PrintK>,
+ Bind<GetEnv<"NODE_ENV">, PrintK>,
+ Bind<JsExpr<"{ boobaa: [5 * 3, 5 * 2] }">, PrintK>,
// ChainIO<ReadLine, WithInputK>,
- ChainIO<ReadFile<"./default.nix">, PrintK>,
+ Bind<ReadFile<"./default.nix">, PrintK>,
PutString<"Your name? ">,
- // ChainIO<ReadLine, PrintK<"Hello,">>,
+ Bind<ReadLine, PrintK<"Hello,">>,
]>
diff --git a/src/runtime.ts b/src/runtime.ts
index f066df9..dae492c 100644
--- a/src/runtime.ts
+++ b/src/runtime.ts
@@ -71,7 +71,7 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> =>
return [hash]
},
- ChainIO: async () => {
+ Bind: async () => {
const inputTyp = effTyp.getProperty('input')?.getTypeAtLocation(node)
const inputResults = inputTyp && await accumulateResults(inputTyp, node)
return inputResults ?? []
@@ -149,7 +149,7 @@ const evalAccumulator = async (effNode: Node, node: Node) => {
await fs.writeFile(filePath, contents)
},
- ChainIO: async () => {
+ Bind: async () => {
const chainToKind = effTyp.getProperty('chainTo')?.getTypeAtLocation(node)
const [hashRes] = await accumulateResults(effTyp, node)
const chainRes = `(${typeToString(chainToKind)} & { input: ${RESULT_TYPE_NAME}[${JSON.stringify(hashRes)}]['output'] })['return']`
diff --git a/src/stdlib/fs.ts b/src/stdlib/fs.ts
new file mode 100644
index 0000000..0bd6a2c
--- /dev/null
+++ b/src/stdlib/fs.ts
@@ -0,0 +1,6 @@
+import { EffectAtom } from './io'
+
+export interface WriteFile<_Path extends string, _Content extends string> extends EffectAtom { }
+
+export interface ReadFile<_Path extends string> extends EffectAtom<string> { }
+
diff --git a/src/stdlib/index.ts b/src/stdlib/index.ts
new file mode 100644
index 0000000..45197d9
--- /dev/null
+++ b/src/stdlib/index.ts
@@ -0,0 +1,4 @@
+export * from './io'
+export * from './fs'
+export * from './stdio'
+export * from './sys'
diff --git a/src/stdlib/io.ts b/src/stdlib/io.ts
new file mode 100644
index 0000000..00b74b1
--- /dev/null
+++ b/src/stdlib/io.ts
@@ -0,0 +1,18 @@
+export interface EffectAtom<T = unknown> { output: T }
+export type Effect = EffectAtom[]
+
+export interface Kind1<Inp = unknown, Out = unknown> {
+ input: Inp
+ return: Out
+}
+
+export interface Program<Effs extends Effect, ExitCode extends number = 0> {
+ effects: Effs,
+ exitCode: ExitCode,
+}
+
+export interface Bind<Eff extends EffectAtom, Fn extends Kind1> extends EffectAtom {
+ input: Eff
+ chainTo: Fn
+}
+
diff --git a/src/stdlib/stdio.ts b/src/stdlib/stdio.ts
new file mode 100644
index 0000000..96c27f8
--- /dev/null
+++ b/src/stdlib/stdio.ts
@@ -0,0 +1,10 @@
+import { EffectAtom } from './io'
+
+export interface PutString<_ extends string> extends EffectAtom { }
+
+export interface Print<_ extends any> extends EffectAtom { }
+
+export interface Debug<_ extends string, T> extends EffectAtom<T> { }
+
+export interface ReadLine extends EffectAtom<string> { }
+
diff --git a/src/stdlib/sys.ts b/src/stdlib/sys.ts
new file mode 100644
index 0000000..1a9b18e
--- /dev/null
+++ b/src/stdlib/sys.ts
@@ -0,0 +1,8 @@
+import { EffectAtom } from './io'
+
+export interface GetEnv<_Name extends string> extends EffectAtom<string> { }
+
+export interface GetArgs extends EffectAtom<string[]> { }
+
+export interface JsExpr<_Expr extends string> extends EffectAtom<any> { }
+