diff options
| -rw-r--r-- | examples/file.ts | 25 | ||||
| -rw-r--r-- | examples/greeting.ts | 5 | ||||
| -rw-r--r-- | src/context.ts | 4 | ||||
| -rw-r--r-- | src/eval-env/builtins.ts | 15 | ||||
| -rw-r--r-- | src/types.ts | 12 | ||||
| -rw-r--r-- | stdlib/effect.ts | 7 |
6 files changed, 39 insertions, 29 deletions
diff --git a/examples/file.ts b/examples/file.ts index fb38613..ccb8a66 100644 --- a/examples/file.ts +++ b/examples/file.ts @@ -8,21 +8,24 @@ interface PrintK extends Kind1<string> { } export type main = [ - Do<[ - BindTo<"contents", ReadFile<'./bin.js'>>, - PutStringLn<"------">, - Bind<Label<"contents">, <c extends string>() => PutStringLn<c>>, - ]>, + Do< + [ + BindTo<'contents', ReadFile<'./bin.js'>>, + PutStringLn<'------'>, + Bind<Label<'contents'>, <c extends string>() => PutStringLn<c>> + ] + >, - Try<Bind<Label<"contents">, PrintK>, <e extends string>() => - PutStringLn<`ERROR: ${e}`>>, + Try< + Bind<Label<'contents'>, PrintK>, + <e extends string>() => PutStringLn<`ERROR: ${e}`> + >, - PutStringLn<"-------------">, + PutStringLn<'-------------'>, - Bind<ReadFile<'./default.nix'>, <c extends string>() => - PutStringLn<c>>, + Bind<ReadFile<'./default.nix'>, <c extends string>() => PutStringLn<c>>, - PutStringLn<"-------------">, + PutStringLn<'-------------'>, Try< Bind<ReadFile<'./unicorn'>, PrintK>, diff --git a/examples/greeting.ts b/examples/greeting.ts index 8ed2181..72edde2 100644 --- a/examples/greeting.ts +++ b/examples/greeting.ts @@ -10,12 +10,11 @@ export type main = [ PutStringLn<'----------------'>, PutString<'Your name? '>, - Bind<ReadLine, <name extends string>() => - PutStringLn<`Hello, ${name}`>>, + Bind<ReadLine, <name extends string>() => PutStringLn<`Hello, ${name}`>>, PutStringLn<'----------------'>, PutString<'Your purpose in life? '>, Bind<ReadLine, ResponseK>, - PutStringLn<'----------------'>, + PutStringLn<'----------------'> ] diff --git a/src/context.ts b/src/context.ts index adc0be5..fe33731 100644 --- a/src/context.ts +++ b/src/context.ts @@ -116,7 +116,7 @@ export const createContext = (options: CtxOptions): Ctx => { evaluateType, newScope() { - environment.unshift(new Map) + environment.unshift(new Map()) }, addToScope(name, resKey) { if (environment.length === 0) ctx.newScope() @@ -127,7 +127,7 @@ export const createContext = (options: CtxOptions): Ctx => { environment.shift() }, getKeyInScope(name) { - return environment.find(scope => scope.has(name))?.get(name) + return environment.find((scope) => scope.has(name))?.get(name) }, withScope: (fn) => async () => { ctx.newScope() diff --git a/src/eval-env/builtins.ts b/src/eval-env/builtins.ts index 1ded638..669a005 100644 --- a/src/eval-env/builtins.ts +++ b/src/eval-env/builtins.ts @@ -4,7 +4,9 @@ import { evalList } from '../util' const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type => { const resultType = (() => { - const baseTypes = fn?.getBaseTypes().flatMap(t => t.getSymbol()?.getName()) + const baseTypes = fn + ?.getBaseTypes() + .flatMap((t) => t.getSymbol()?.getName()) if (baseTypes?.includes('Kind1')) { const [_, resultNode] = ctx.createResult( @@ -15,7 +17,9 @@ const applyFunc = (ctx: Ctx, fn: Type | undefined, val: string): Type => { .getProperty('output') ?.getTypeAtLocation(resultNode) } else { - const [_key, resultNode] = ctx.createResult(`ReturnType<${ctx.typeToString(fn)}>`) + const [_key, resultNode] = ctx.createResult( + `ReturnType<${ctx.typeToString(fn)}>` + ) const resValueNode = resultNode ?.asKind(SyntaxKind.PropertySignature) @@ -129,8 +133,11 @@ export default (ctx: Ctx, args: Type[]) => ({ // TODO: Handle resultKey undefined case - const resultType = - applyFunc(ctx, chainToKind, `(${ctx.getResultExpr(resultKey)})['output']`) + const resultType = applyFunc( + ctx, + chainToKind, + `(${ctx.getResultExpr(resultKey)})['output']` + ) return ctx.evaluateType(ctx, resultType) }), diff --git a/src/types.ts b/src/types.ts index 411c8ed..6ea282e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -29,11 +29,11 @@ export interface Ctx { runCustomEffect: (name: string, args: Type[]) => Promise<string[]> hasCustomEffect: (name: string) => boolean - evaluateType: (ctx: Ctx, effTyp: Type) => Promise<string[]>, + evaluateType: (ctx: Ctx, effTyp: Type) => Promise<string[]> - withScope: (fn: () => Promise<string[]>) => (() => Promise<string[]>), - newScope: () => void, - clearScope: () => void, - addToScope: (name: string, resKey: string) => void, - getKeyInScope: (name: string) => string | undefined, + withScope: (fn: () => Promise<string[]>) => () => Promise<string[]> + newScope: () => void + clearScope: () => void + addToScope: (name: string, resKey: string) => void + getKeyInScope: (name: string) => string | undefined } diff --git a/stdlib/effect.ts b/stdlib/effect.ts index f3ef99e..d53b6b6 100644 --- a/stdlib/effect.ts +++ b/stdlib/effect.ts @@ -7,13 +7,14 @@ export interface Kind1<Inp = unknown, Out = unknown> { return: Out } -export type Func<Inp = unknown, Out = unknown> - = Kind1<Inp, Out> +export type Func<Inp = unknown, Out = unknown> = + | Kind1<Inp, Out> | (<_T extends Inp>() => Out) export interface Bind<_Eff extends Effect, _Fn extends Func> extends Effect {} -export interface BindTo<_Name extends string, _Eff extends Effect> extends Effect {} +export interface BindTo<_Name extends string, _Eff extends Effect> + extends Effect {} export interface Label<_Name extends string> extends Effect {} export interface Seq<_Effs extends Effect[]> extends Effect {} |
