diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/index.ts | 8 | ||||
| -rw-r--r-- | src/runtime.ts | 16 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/index.ts b/src/index.ts index b8a69ac..aad0c00 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,7 +13,7 @@ export interface GetArgs extends EffectAtom<string[]> { } export interface ReadLine extends EffectAtom<string> { } -export interface JsExpr<_Expr extends string> extends EffectAtom<any> {} +export interface JsExpr<_Expr extends string> extends EffectAtom<any> { } export interface Program<Effs extends Effect, ExitCode extends number = 0> { effects: Effs, @@ -34,10 +34,6 @@ interface PrintK<Label extends string = ""> extends Kind1<unknown> { return: Debug<Label, this['input']> } -// interface WithInputK extends Kind1<string> { -// return: ChainIO<ReadLine, PrintK<this['input']>> -// } - export type main = Program<[ ChainIO<GetArgs, PrintK>, [1, 2, 3] extends infer Res ? Print<Res> : never, @@ -46,6 +42,6 @@ export type main = Program<[ // ChainIO<ReadLine, WithInputK>, ChainIO<ReadFile<"./default.nix">, PrintK>, PutString<"Your name? ">, - ChainIO<ReadLine, PrintK<"Hello,">>, + // ChainIO<ReadLine, PrintK<"Hello,">>, ]> diff --git a/src/runtime.ts b/src/runtime.ts index b3c49c3..f066df9 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -3,6 +3,7 @@ import path from 'path' import { promises as fs } from 'fs' import readline from 'readline'; import { stdout } from 'process'; +import { v4 as uuid } from 'uuid'; const rl = readline.createInterface({ input: process.stdin, @@ -54,9 +55,6 @@ const addResult = (name: string, ty: string) => { } } -const createHash = () => - Math.random().toFixed(8).slice(2) - const match = <K extends string, R>(k: K | undefined, pattern: { [key in K | '_']: () => R }) => k && pattern[k] ? pattern[k]() : pattern._() @@ -68,7 +66,7 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> => const [pathTyp] = effTyp.getTypeArguments() const filePath = JSON.parse(typeToString(pathTyp)) const contents = await fs.readFile(filePath, 'utf-8') - const hash = createHash() + const hash = uuid() addResult(hash, JSON.stringify(contents)) return [hash] }, @@ -82,20 +80,20 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> => GetEnv: async () => { const [envTyp] = effTyp.getTypeArguments() const envName = JSON.parse(typeToString(envTyp)) - const hash = createHash() + const hash = uuid() addResult(hash, `${JSON.stringify(process.env[envName] ?? '')}`) return [hash] }, GetArgs: async () => { - const hash = createHash() + const hash = uuid() addResult(hash, `${JSON.stringify(process.argv.slice(2))}`) return [hash] }, ReadLine: async () => { const line = await readLineFromStdin() - const hash = createHash() + const hash = uuid() addResult(hash, `${JSON.stringify(line)}`) return [hash] }, @@ -104,7 +102,7 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> => const [exprTyp] = effTyp.getTypeArguments() const exprStr = JSON.parse(typeToString(exprTyp)) const result = eval(`JSON.stringify(${exprStr})`) - const hash = createHash() + const hash = uuid() addResult(hash, `${result}`) return [hash] }, @@ -159,6 +157,8 @@ const evalAccumulator = async (effNode: Node, node: Node) => { await evalAccumulator(updateEffNode, node) }, + ReplacePlaceholders: async () => { }, + _: async () => { console.log(effNode.print()) console.log('TTTT', typeToString(effTyp)) |
