diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/custom-effect.ts | 15 | ||||
| -rw-r--r-- | examples/ffi.ts | 9 | ||||
| -rw-r--r-- | examples/guess-number.ts | 6 |
3 files changed, 21 insertions, 9 deletions
diff --git a/examples/custom-effect.ts b/examples/custom-effect.ts index 948caf4..6a4b8b0 100644 --- a/examples/custom-effect.ts +++ b/examples/custom-effect.ts @@ -1,10 +1,15 @@ -import { DefineEffect, Effect } from '../src/stdlib' +import { Bind, DefineEffect, Effect, Kind1, Print } from '../src/stdlib' -interface Wow<_A, _B> extends Effect { } +interface Mathemagic<_A, _B> extends Effect { } + +interface PrintK extends Kind1 { + return: Print<this['input']> +} export type main = [ - DefineEffect<"Wow", `(a, b) => { - console.log(typeToString(a), '-->', typeToString(b)) + DefineEffect<"Mathemagic", `(a, b) => { + console.log(typeToString(a)) + return { result: 5 * b.getLiteralValue() } }`>, - Wow<"a", 69>, + Bind<Mathemagic<"a", 69>, PrintK>, ] diff --git a/examples/ffi.ts b/examples/ffi.ts index 7a73a0a..3310712 100644 --- a/examples/ffi.ts +++ b/examples/ffi.ts @@ -1,4 +1,4 @@ -import { Bind, Debug, JsExpr, Kind1 } from "../src/stdlib" +import { Bind, Debug, DefineEffect, Effect, JsExpr, Kind1 } from "../src/stdlib" interface PrintK<Label extends string = ""> extends Kind1 { return: Debug<Label, this['input']> @@ -6,7 +6,14 @@ interface PrintK<Label extends string = ""> extends Kind1 { type Square<N extends number> = JsExpr<`${N} ** 2`> +interface Mathemagic<_A, _B extends number> extends Effect { } + export type main = [ Bind<JsExpr<"{ boobaa: [5 * 3, 5 * 2] }">, PrintK<'|'>>, Bind<Square<69>, PrintK<"69^2 =">>, + DefineEffect<"Mathemagic", `(a, b) => { + console.log(typeToString(a)) + return { result: 5 * b.getLiteralValue() } + }`>, + Bind<Mathemagic<"a", 69>, PrintK<'69 * 5 ='>>, ] diff --git a/examples/guess-number.ts b/examples/guess-number.ts index 8f5d535..79f6ad1 100644 --- a/examples/guess-number.ts +++ b/examples/guess-number.ts @@ -1,4 +1,4 @@ -import { Print, PutString, Bind, Kind1, JsExpr, ReadLine, Then, PutStringLn } from '../src/stdlib' +import { Print, PutString, Bind, Kind1, JsExpr, ReadLine, Do, PutStringLn } from '../src/stdlib' export type main = [ PutStringLn<"You have 5 guesses">, @@ -11,7 +11,7 @@ export type main = [ interface AskForGuess<N extends number, Attempts extends 0[]> extends Kind1<string> { return: `${this['input']}` extends `${N}` ? PutStringLn<"Yay! You got it right!"> - : Then<[ + : Do<[ Print<`Wrong guess. Total attempts: ${ [...Attempts, 0] extends infer Ls extends 0[] ? Ls['length'] : 0 }`>, @@ -23,7 +23,7 @@ interface StartGuessing<Attempts extends 0[] = []> extends Kind1<number> { return: Attempts['length'] extends 5 ? PutStringLn<"Max attempts exceeded. Game over!"> : Bind< - Then<[ + Do<[ PutString<"Your guess? ">, ReadLine ]>, |
