UNPKG

@effectful/cc

Version:

Multi-prompt delimited continuations runtime

75 lines (74 loc) 3.46 kB
import { Prompt, SubCont, newPrompt } from "./types"; export { newPrompt, SubCont as SubCont, Prompt }; /** * uses prompt in its first operand to delimit the current continuation during * the evaluation of its second operand. */ export declare function pushPrompt<A>(_prompt: Prompt<A>, body: () => A): A; /** * composes sub-continuation `subk` with current continuation and evaluates * its second argument `body` */ export declare function pushSubCont<A, B>(subk: SubCont<A, B>, body: () => A): B; /** * Captures a portion of the current continuation back to * but not including the activation of pushPrompt with prompt `prompt`, aborts the * current continuation back to and including the activation of `pushPrompt`, and * invokes `body`, passing it an abstract value representing the captured subcontinuation. * If more than one activation of pushPrompt with prompt `prompt` is still active, * the most recent enclosing activation, i.e., the one that delimits the smallest * subcontinuation, is selected. */ export declare function withSubCont<A, B>(prompt: Prompt<B>, body: (seg: SubCont<A, B>) => B): A; /** * caputes and aborts the current continuation until prompt `p` and calls `f` * passing captured continuation as a function to its argument, * delimits captured and resulting continuations */ export declare function shift<A, B>(prompt: Prompt<B>, body: (k: (v: () => A) => B) => B): A; /** * caputes and aborts the current continuation until prompt `p` and calls `f` * passing captured continuation as a function to its argument, * deoesn't delimit captured, delimits resultinging continuation */ export declare function control<A, B>(prompt: Prompt<B>, body: (k: (v: () => A) => B) => B): A; /** * caputes and aborts the current continuation until prompt `prompt` and calls `body` * passing captured continuation as a function to its argument, * delimits captured, doesn't delimit resultinging continuation */ export declare function shift0<A, B>(prompt: Prompt<B>, body: (k: (v: () => A) => B) => B): A; /** * caputes and aborts the current continuation until prompt `prompt` and calls `body` * passing captured continuation as a function to its argument, * doesn't delimit captured and resulting continuations */ export declare function control0<A, B>(prompt: Prompt<B>, body: (k: (v: () => A) => B) => B): A; /** * Creates a new prompt and calls the `body` function, passing this new prompt as an argument. * The resulting continuation is delimited by the new prompt. */ export declare function reset<A>(body: (prompt: Prompt<A>) => A): A; /** * Aborts the current continuation up to the specified prompt `prompt`. * * @param prompt - The prompt up to which the continuation is aborted. * @param result - The value to return after aborting the continuation. * @returns This should never exit */ export declare function abort<B, A = any>(prompt: Prompt<B>, result: B): A; /** * Composes a series of functions into a single function. * * @param funs - A list of functions to compose. * @returns A function that applies the composed functions to a value. */ export declare function pipe(...funs: ((a: any) => any)[]): (arg: any) => any; /** * Applies a series of functions to a value in sequence. * * @param val - The initial value. * @param funs - A list of functions to apply to the value. * @returns The final value. */ export declare function chain(val: any, ...funs: ((a: any) => any)[]): any;