diff --git a/eslint.config.mjs b/eslint.config.mjs index e104470..a166a5a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -34,6 +34,7 @@ export default [ '@stylistic/semi': ['error', 'always'], '@stylistic/indent': 'error', '@stylistic/arrow-parens': ['error', 'as-needed', { requireForBlockBody: false }], + '@stylistic/max-statements-per-line': 'off', '@typescript-eslint/no-unused-vars': [ 'error', { diff --git a/src/bool.ts b/src/bool.ts index fbb9155..2d93130 100644 --- a/src/bool.ts +++ b/src/bool.ts @@ -1,8 +1,8 @@ -import { toNative as $$, L, P, _, fromNative as __, id, pipe } from './core'; +import { toNative as $$, L, _, fromNative as __, id, pipe } from './core'; import { EQ, GT, LT, Ord } from './ord'; import { String, fromString as _s } from './string'; -export type Bool = L<(t: T) => L<(f: T) => T>>; +export type Bool = L<(t: T) => L<(f: T) => T>>; export const True: Bool = _(t => _(_f => t)) as Bool; @@ -10,7 +10,7 @@ export const True: Bool export const False: Bool = _(_t => _(f => f)); -export const iif: L<(b: Bool) => L<(t: T) => L<(f: T) => T>>> +export const iif: L<(b: Bool) => L<(t: T) => L<(f: T) => T>>> = id; export const not: L<(b: Bool) => Bool> diff --git a/src/core.ts b/src/core.ts index 0c40cb0..4687634 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,36 +1,29 @@ -export type L L> = T & { run: () => T }; +type F = (v: L) => L; -export function ___ L>(run: () => T): L { - const r: T = ((p: Parameters[0]) => { - let v: any; - return ___(() => run()( - ___(() => v ??= p.run()), - ).run()); - }) as T; +export type L = T & { run: () => T }; - (r as L).run = run; +const defer: (run: () => T) => L = (run: () => T) => + Object.assign(((p: Parameters[0]): ReturnType => { + let v: F; + return defer(() => run()(defer(() => v ??= p.run())).run()); + }) as T, { run }); - return r as L; -} - -export type P = L<(v: unknown) => L>; - -export const _ = L)>(v: T): L => ___(() => v); +export const _ = (v: T): L => defer(() => v); export const fromNative: (v: T) => L - = v => ___(() => v as any); + = v => defer(() => v as any); export const toNative: (v: L) => T = (v: L) => v.run() as T; -export const undef: any = ___(() => { - throw new Error('undefined'); -}); +export const y = (f: () => L) => defer(() => f().run()); + +export const undef: any = defer(() => { throw new Error('undefined'); }); -export const id: L<(v: T) => T> +export const id: L<(v: T) => T> = _(v => v); -export const cnst: L<(v: T) => L<(_: unknown) => T>> - = _(v => _(_ => v)) as L<(v: T) => L<(_: unknown) => T>>; -export const pipe: L<(f: L<(v: B) => C>) => L<(g: L<(v: A) => B>) => L<(v: A) => C>>> - = _((f: L<(v: B) => C>) => +export const cnst: L<(v: T) => L<(_: unknown) => T>> + = _(v => _(_ => v)) as L<(v: T) => L<(_: unknown) => T>>; +export const pipe: L<(f: L<(v: B) => C>) => L<(g: L<(v: A) => B>) => L<(v: A) => C>>> + = _((f: L<(v: B) => C>) => _((g: L<(v: A) => B>) => _((v: A) => f(g(v))))); diff --git a/src/debug.ts b/src/debug.ts index 4eed77d..c742f48 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -1,7 +1,7 @@ -import { L, P, _ } from './core'; +import { L, _ } from './core'; import { String, toString } from './string'; -export const log: L<(s: String) => L<(p: T) => T>> +export const log: L<(s: String) => L<(p: T) => T>> = _(s => _(p => { console.log(toString(s)); return p; diff --git a/src/index.ts b/src/index.ts index af8fdef..04f5982 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,7 @@ -import { toNative as $$, _, fromNative as __, id } from './core'; +import { _, fromNative as __ } from './core'; +import { toString as $s, fromString as _s } from './string'; +import { run } from './bf'; -console.log($$(id(__('first')))); +console.log($s(run +(_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.')) +(_s('')))); diff --git a/src/list.ts b/src/list.ts index 68b1b7e..ec7be7b 100644 --- a/src/list.ts +++ b/src/list.ts @@ -1,69 +1,69 @@ -import { toNative as $$, L, P, _, fromNative as __, ___, cnst, id, pipe, undef } from './core'; +import { toNative as $$, L, _, fromNative as __, cnst, id, pipe, undef, y } from './core'; import { EQ, GT, LT, Ord, eq as eqc } from './ord'; import { Bool, False, True, and, iif, or } from './bool'; import { Num, Zero, succ } from './num'; import { String, fromString as _s } from './string'; -export type List = L<(z: R) => L<(f: L<(x: T) => L<(xs: List) => R>>) => R>>; +export type List = L<(z: R) => L<(f: L<(x: T) => L<(xs: List) => R>>) => R>>; export const Nil: List = _(z => _(_f => z)) as List; -export const Cons: L<(x: T) => L<(xs: List) => List>> - = _((x: T) => _((xs: List) => _(_z => _(f => f(x)(xs))) as List)); +export const Cons: L<(x: T) => L<(xs: List) => List>> + = _((x: T) => _((xs: List) => _(_z => _(f => f(x)(xs))) as List)); -export const cons: L<(x: T) => L<(xs: List) => List>> +export const cons: L<(x: T) => L<(xs: List) => List>> = Cons; -export const snoc: L<(xs: List) => L<(x: T) => List>> - = _((xs: List) => +export const snoc: L<(xs: List) => L<(x: T) => List>> + = _((xs: List) => _((x: T) => xs(cons(x)(Nil))(_(y => _(ys => cons(y)(snoc(ys)(x))))))); -export const nul: L<(xs: List) => Bool> +export const nul: L<(xs: List) => Bool> = _(xs => xs(True)(cnst(cnst(False)))); -export const len: L<(xs: List) => Num> +export const len: L<(xs: List) => Num> = _(xs => xs(Zero)(cnst(pipe(succ)(len)))); -export const singleton: L<(v: T) => List> +export const singleton: L<(v: T) => List> = _(x => cons(x)(Nil)); -export const append: L<(l: List) => L<(r: List) => List>> +export const append: L<(l: List) => L<(r: List) => List>> = _(l => _(r => l(r)(_(x => _(xs => cons(x)(append(xs)(r))))))); -export const concat: L<(ls: List>) => List> +export const concat: L<(ls: List>) => List> = _(ls => ls(Nil)(_(x => pipe(append(x))(concat)))); -export const repeat: L<(x: T) => List> +export const repeat: L<(x: T) => List> = _(x => cons(x)(repeat(x))); -export const iterate: L<(f: L<(x: T) => T>) => L<(x: T) => List>> - = _((f: L<(x: T) => T>) => _((x: T) => cons(x)(iterate(f)(f(x))))); +export const iterate: L<(f: L<(x: T) => T>) => L<(x: T) => List>> + = _((f: L<(x: T) => T>) => _((x: T) => cons(x)(iterate(f)(f(x))))); -export const head: L<(xs: List) => T> +export const head: L<(xs: List) => T> = _(xs => xs(undef)(cnst)); -export const tail: L<(xs: List) => List> +export const tail: L<(xs: List) => List> = _(xs => xs(undef)(cnst(id))); -export const foldl: L<(f: L<(a: R) => L<(x: T) => R>>) => L<(z: R) => L<(xs: List) => R>>> - = _((f: L<(a: R) => L<(x: T) => R>>) => +export const foldl: L<(f: L<(a: R) => L<(x: T) => R>>) => L<(z: R) => L<(xs: List) => R>>> + = _((f: L<(a: R) => L<(x: T) => R>>) => _((z: R) => _((xs: List) => xs(z)(pipe(foldl(f))(f(z)))))); -export const foldlz: L<(f: L<(a: T) => L<(x: T) => T>>) => L<(xs: List) => T>> - = _((f: L<(a: T) => L<(x: T) => T>>) => _((xs: List) => xs(undef)(foldl(f)))); +export const foldlz: L<(f: L<(a: T) => L<(x: T) => T>>) => L<(xs: List) => T>> + = _((f: L<(a: T) => L<(x: T) => T>>) => _((xs: List) => xs(undef)(foldl(f)))); -export const foldr: L<(f: L<(x: T) => L<(a: R) => R>>) => L<(z: R) => L<(xs: List) => R>>> - = _((f: L<(x: T) => L<(a: R) => R>>) => +export const foldr: L<(f: L<(x: T) => L<(a: R) => R>>) => L<(z: R) => L<(xs: List) => R>>> + = _((f: L<(x: T) => L<(a: R) => R>>) => _((z: R) => _((xs: List) => xs(z)(_(x => pipe(f(x))(foldr(f)(z))))))); -export const foldrz: L<(f: L<(x: T) => L<(a: T) => T>>) => L<(xs: List) => T>> +export const foldrz: L<(f: L<(x: T) => L<(a: T) => T>>) => L<(xs: List) => T>> = undef; -export const cmp: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Ord>>> - = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => +export const cmp: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Ord>>> + = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => _((l: List) => _((r: List) => l (r(EQ)(cnst(cnst(LT)))) @@ -72,73 +72,73 @@ export const cmp: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: (cmp(ecmp)(lxs)(rxs)) (ecmp(lx)(rx))))))))))); -export const lt: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> - = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => +export const lt: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> + = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => _((l: List) => _((r: List) => r(False)(_(rx => _(rxs => l(True)(_(lx => _(lxs => ecmp(lx)(rx)(True)(lt(ecmp)(lxs)(rxs))(False)))))))))); -export const le: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> - = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => +export const le: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> + = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => _((l: List) => _((r: List) => l(True)(_(lx => _(lxs => r(False)(_(rx => _(rxs => ecmp(lx)(rx)(True)(le(ecmp)(lxs)(rxs))(False)))))))))); -export const eq: L<(eeq: L<(l: T) => L <(r: T) => Bool>>) => L<(l: List) => L<(r: List) => Bool>>> - = _((eeq: L<(l: T) => L<(r: T) => Bool>>) => +export const eq: L<(eeq: L<(l: T) => L <(r: T) => Bool>>) => L<(l: List) => L<(r: List) => Bool>>> + = _((eeq: L<(l: T) => L<(r: T) => Bool>>) => _((l: List) => _((r: List) => l (r(True)(cnst(cnst(False)))) (_(lx => _(lxs => r(False)(_(rx => _(rxs => and(eeq(lx)(rx))(eq(eeq)(lxs)(rxs))))))))))); -export const ge: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> - = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => +export const ge: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> + = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => _((l: List) => _((r: List) => r(True)(_(rx => _(rxs => l(False)(_(lx => _(lxs => ecmp(lx)(rx)(False)(ge(ecmp)(lxs)(rxs))(True)))))))))); -export const gt: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> - = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => +export const gt: L<(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List) => L<(r: List) => Bool>>> + = _((ecmp: L<(l: T) => L<(r: T) => Ord>>) => _((l: List) => _((r: List) => l(False)(_(lx => _(lxs => r(True)(_(rx => _(rxs => ecmp(lx)(rx)(False)(gt(ecmp)(lxs)(rxs))(True)))))))))); -export const map: L<(f: L<(x: T) => R>) => L<(xs: List) => List>> - = _((f: L<(x: T) => R>) => +export const map: L<(f: L<(x: T) => R>) => L<(xs: List) => List>> + = _((f: L<(x: T) => R>) => _((xs: List) => xs(Nil)(_(x => pipe(cons(f(x)))(map(f)))))); -export const filter: L<(f: L<(x: T) => Bool>) => L<(xs: List) => List>> - = _((f: L<(x: T) => Bool>) => +export const filter: L<(f: L<(x: T) => Bool>) => L<(xs: List) => List>> + = _((f: L<(x: T) => Bool>) => _((xs: List) => xs(Nil)(_(x => pipe(iif(f(x))(cons(x))(id))(filter(f)))))); -export const any: L<(f: L<(x: T) => Bool>) => L<(xs: List) => Bool>> - = _((f: L<(x: T) => Bool>) => +export const any: L<(f: L<(x: T) => Bool>) => L<(xs: List) => Bool>> + = _((f: L<(x: T) => Bool>) => _((xs: List) => xs(False)(_(x => pipe(or(f(x)))(any(f)))))); -export const all: L<(f: L<(x: T) => Bool>) => L<(xs: List) => Bool>> - = _((f: L<(x: T) => Bool>) => +export const all: L<(f: L<(x: T) => Bool>) => L<(xs: List) => Bool>> + = _((f: L<(x: T) => Bool>) => _((xs: List) => xs(True)(_(x => pipe(and(f(x)))(all(f)))))); -export const get: L<(i: Num) => L<(xs: List) => T>> +export const get: L<(i: Num) => L<(xs: List) => T>> = _(i => _(xs => xs(undef)(_(x => i(cnst(x))(get))))); -export const update: L<(f: L< (p: T) => T>) => L<(i: Num) => L<(xs: List) => List>>> - = _((f: L< (p: T) => T>) => +export const update: L<(f: L< (p: T) => T>) => L<(i: Num) => L<(xs: List) => List>>> + = _((f: L< (p: T) => T>) => _((i: Num) => _((xs: List) => xs(undef)(_(x => _(xs => i(cons(f(x))(xs))(_(pi => cons(x)(update(f)(pi)(xs)))))))))); -export const set: L<(v: T) => L<(i: Num) => L<(xs: List) => List>>> +export const set: L<(v: T) => L<(i: Num) => L<(xs: List) => List>>> = pipe(update)(cnst); -export const intersperse: L<(v: T) => L<(xs: List) => List>> +export const intersperse: L<(v: T) => L<(xs: List) => List>> = _(v => _(xs => xs(xs)(_(x => _(rxs => rxs(xs)(cnst(cnst(cons(x)(cons(v)(intersperse(v)(rxs))))))))))); -export const show: L<(eshow: L<(e: T) => String>) => L<(xs: List) => String>> +export const show: L<(eshow: L<(e: T) => String>) => L<(xs: List) => String>> = _(eshow => _(xs => concat(snoc(cons(_s('['))(intersperse(_s(', '))(map(eshow)(xs))))(_s(']'))))); -export const fromArray: (xs: T[]) => List - = xs => xs.length === 0 ? Nil : cons(xs[0])(___(() => fromArray(xs.slice(1)).run())); +export const fromArray: (xs: T[]) => List + = xs => xs.length === 0 ? Nil : cons(xs[0])(y(() => fromArray(xs.slice(1)))); -export const toArray: (xs: List) => P[] +export const toArray: (xs: List) => L[] = xs => $$(xs(__([]))(_(x => _(xs => __([x, ...toArray(xs)]))))); diff --git a/src/num.ts b/src/num.ts index 70c9dab..363046e 100644 --- a/src/num.ts +++ b/src/num.ts @@ -1,9 +1,9 @@ -import { toNative as $$, L, P, _, fromNative as __, ___, cnst, id, pipe } from './core'; +import { toNative as $$, L, _, fromNative as __, cnst, id, pipe, y } from './core'; import { EQ, GT, LT, Ord } from './ord'; import { Bool, False, True, iif } from './bool'; import { Empty, String, append, cons } from './string'; -export type Num = L<(z: T) => L<(n: L<(p: Num) => T>) => T>>; +export type Num = L<(z: T) => L<(n: L<(p: Num) => T>) => T>>; export const Zero: Num = _(z => _(_n => z)) as Num; @@ -11,7 +11,7 @@ export const Zero: Num export const Succ: L<(p: Num) => Num> = _(p => _(_z => _(n => n(p)))); -export const ifz: L<(n: Num) => L<(t: T) => L<(f: T) => T>>> +export const ifz: L<(n: Num) => L<(t: T) => L<(f: T) => T>>> = _(n => _(t => _(f => n(t)(cnst(f))))); export const succ: L<(n: Num) => Num> @@ -65,7 +65,7 @@ export const show: L<(n: Num) => String> (append(show(div(n)(fromNumber(10))))(show(mod(n)(fromNumber(10)))))); export const fromNumber: (n: number) => Num - = n => !n ? Zero : Succ(___(() => fromNumber(n - 1).run())); + = n => !n ? Zero : Succ(y(() => fromNumber(n - 1))); export const toNumber: (n: Num) => number = n => $$(n(__(0))(_(p => __(1 + toNumber(p))))); diff --git a/src/ord.ts b/src/ord.ts index f629360..6e39e8e 100644 --- a/src/ord.ts +++ b/src/ord.ts @@ -1,8 +1,8 @@ -import { toNative as $$, L, P, _, fromNative as __ } from './core'; +import { toNative as $$, L, _, fromNative as __ } from './core'; import { Bool, False, True } from './bool'; import { String, fromString as _s } from './string'; -export type Ord = L<(lt: T) => L<(eq: T) => L<(gt: T) => T>>>; +export type Ord = L<(lt: T) => L<(eq: T) => L<(gt: T) => T>>>; export const enum NOrd { LT, diff --git a/src/pair.ts b/src/pair.ts index e04e1cc..01657e4 100644 --- a/src/pair.ts +++ b/src/pair.ts @@ -1,82 +1,82 @@ -import { L, P, _ } from './core'; +import { L, _ } from './core'; import { GT, LT, Ord } from './ord'; import { Bool, False, True, and } from './bool'; import { Nil, concat, cons } from './list'; import { String, fromString as _s } from './string'; -export type Pair = L<(f: L<(f: F) => L<(s: S) => R>>) => R>; +export type Pair = L<(f: L<(f: F) => L<(s: S) => R>>) => R>; -export const Pair: L<(f: F) => L<(s: S) => Pair>> - = _((f: F) => +export const Pair: L<(f: F) => L<(s: S) => Pair>> + = _((f: F) => _((s: S) => - _((p: L<(f: F) => L<(s: S) => R>>) => p(f)(s)))); + _((p: L<(f: F) => L<(s: S) => R>>) => p(f)(s)))); -export const fst: L<(p: Pair) => F> +export const fst: L<(p: Pair) => F> = _(p => p(_(f => _(_s => f)))); -export const snd: L<(p: Pair) => S> +export const snd: L<(p: Pair) => S> = _(p => p(_(_f => _(s => s)))); -export const first: L<(t: L<(f: F) => FR>) => L<(p: Pair) => Pair>> - = _((t: L<(f: F) => FR>) => - _((p: Pair) => p(_(f => _(s => Pair(t(f))(s)))))); +export const first: L<(t: L<(f: F) => FR>) => L<(p: Pair) => Pair>> + = _((t: L<(f: F) => FR>) => + _((p: Pair) => p(_(f => _(s => Pair(t(f))(s)))))); -export const second: L<(t: L<(s: S) => SR>) => L<(p: Pair) => Pair>> - = _((t: L<(s: S) => SR>) => - _((p: Pair) => p(_(f => _(s => Pair(f)(t(s))))))); +export const second: L<(t: L<(s: S) => SR>) => L<(p: Pair) => Pair>> + = _((t: L<(s: S) => SR>) => + _((p: Pair) => p(_(f => _(s => Pair(f)(t(s))))))); -export const both: L<(tf: L<(f: F) => FR>) => L<(ts: L<(s: S) => SR>) => L<(p: Pair) => Pair>>> - = _((tf: L<(f: F) => FR>) => - _((ts: L<(s: S) => SR>) => +export const both: L<(tf: L<(f: F) => FR>) => L<(ts: L<(s: S) => SR>) => L<(p: Pair) => Pair>>> + = _((tf: L<(f: F) => FR>) => + _((ts: L<(s: S) => SR>) => _((p: Pair) => p(_(f => _(s => Pair(tf(f))(ts(s)))))))); -export const uncurry: L<(t: L<(f: F) => L<(s: S) => R>>) => L<(p: Pair) => R>> - = _((t: L<(f: F) => L<(s: S) => R>>) => +export const uncurry: L<(t: L<(f: F) => L<(s: S) => R>>) => L<(p: Pair) => R>> + = _((t: L<(f: F) => L<(s: S) => R>>) => _((p: Pair) => p(t))); -export const cmp: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Ord>>) => L<(l: Pair) => L<(r: Pair) => Ord>>>> - = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => +export const cmp: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Ord>>) => L<(l: Pair) => L<(r: Pair) => Ord>>>> + = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => _((scmp: L<(l: S) => L<(r: S) => Ord>>) => uncurry(_((lf: F) => _((ls: S) => uncurry(_((rf: F) => _((rs: S) => fcmp(lf)(rf)(LT)(scmp(ls)(rs))(GT))))))))); -export const lt: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> - = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => +export const lt: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> + = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => _((scmp: L<(l: S) => L<(r: S) => Ord>>) => uncurry(_((lf: F) => _((ls: S) => uncurry(_((rf: F) => _((rs: S) => fcmp(lf)(rf)(True)(scmp(ls)(rs)(True)(False)(False))(False))))))))); -export const le: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> - = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => +export const le: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> + = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => _((scmp: L<(l: S) => L<(r: S) => Ord>>) => uncurry(_((lf: F) => _((ls: S) => uncurry(_((rf: F) => _((rs: S) => fcmp(lf)(rf)(True)(scmp(ls)(rs)(True)(True)(False))(False))))))))); -export const eq: L<(feq: L<(l: F) => L<(r: F) => Bool>>) => L<(seq: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> - = _((feq: L<(l: F) => L<(r: F) => Bool>>) => +export const eq: L<(feq: L<(l: F) => L<(r: F) => Bool>>) => L<(seq: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> + = _((feq: L<(l: F) => L<(r: F) => Bool>>) => _((seq: L<(l: S) => L<(r: S) => Bool>>) => uncurry(_((lf: F) => _((ls: S) => uncurry(_((rf: F) => _((rs: S) => and(feq(lf)(rf))(seq(ls)(rs)))))))))); -export const ge: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> - = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => +export const ge: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> + = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => _((scmp: L<(l: S) => L<(r: S) => Ord>>) => uncurry(_((lf: F) => _((ls: S) => uncurry(_((rf: F) => _((rs: S) => fcmp(lf)(rf)(False)(scmp(ls)(rs)(False)(True)(True))(True))))))))); -export const gt: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> - = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => +export const gt: L<(fcmp: L<(l: F) => L<(r: F) => Ord>>) => L<(scmp: L<(l: S) => L<(r: S) => Bool>>) => L<(l: Pair) => L<(r: Pair) => Bool>>>> + = _((fcmp: L<(l: F) => L<(r: F) => Ord>>) => _((scmp: L<(l: S) => L<(r: S) => Ord>>) => uncurry(_((lf: F) => _((ls: S) => uncurry(_((rf: F) => _((rs: S) => fcmp(lf)(rf)(False)(scmp(ls)(rs)(False)(False)(True))(True))))))))); -export const show: L<(fshow: L<(f: F) => String>) => L<(sshow: L<(s: S) => String>) => L<(p: Pair) => String>>> - = _((fshow: L<(f: F) => String>) => - _((sshow: L<(s: S) => String>) => +export const show: L<(fshow: L<(f: F) => String>) => L<(sshow: L<(s: S) => String>) => L<(p: Pair) => String>>> + = _((fshow: L<(f: F) => String>) => + _((sshow: L<(s: S) => String>) => uncurry(_((f: F) => _((s: S) => concat(cons(_s('('))(cons(fshow(f))(cons(_s(', '))(cons(sshow(s))(cons(_s(')'))(Nil))))))))))); diff --git a/src/string.ts b/src/string.ts index 3cd1e0a..2f5825c 100644 --- a/src/string.ts +++ b/src/string.ts @@ -1,4 +1,4 @@ -import { toNative as $$, L, _, fromNative as __, ___ } from './core'; +import { toNative as $$, L, _, fromNative as __, y } from './core'; import { Ord } from './ord'; import { Bool } from './bool'; import { fromNumber as _nn } from './num'; @@ -31,7 +31,7 @@ export const wrap: L<(w: String) => L<(c: String) => String>> = _(w => _(c => append(w)(append(c)(w)))); export const fromString: (xs: string) => String - = xs => xs.length === 0 ? Nil : Cons(_c(xs[0]))(___(() => fromString(xs.slice(1)).run())); + = xs => xs.length === 0 ? Nil : Cons(_c(xs[0]))(y(() => fromString(xs.slice(1)))); export const toString: (xs: String) => string = xs => $$(xs(__(''))(_(x => _(xs => __($c(x) + toString(xs)))))); diff --git a/test/list.spec.ts b/test/list.spec.ts index e5c6bc9..a2d25be 100644 --- a/test/list.spec.ts +++ b/test/list.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from '@jest/globals'; -import { toNative as $$, _, fromNative as __, ___, undef } from '../src/core'; +import { toNative as $$, _, fromNative as __, undef, y } from '../src/core'; import { toNOrd as $o, NOrd } from '../src/ord'; import { toBoolean as $b, iif } from '../src/bool'; import { toNumber as $n, toNumber as $nn, Num, Succ, Zero, fromNumber as _n, fromNumber as _nn, cmp as cmpn, eq as eqn, even, gt as ngt, show as nshow, odd, succ, sum } from '../src/num'; @@ -11,7 +11,7 @@ describe('List', () => { const infinite: List = iterate(Succ)(Zero); const _na: (xs: number[]) => List - = xs => xs.length === 0 ? Nil : Cons(_nn(xs[0]))(___(() => _na(xs.slice(1)).run())); + = xs => xs.length === 0 ? Nil : Cons(_nn(xs[0]))(y(() => _na(xs.slice(1)))); const $na: (xs: List) => number[] = xs => $$(xs(__([]))(_(x => _(xs => __([$nn(x), ...$na(xs)]))))); @@ -158,7 +158,7 @@ describe('List', () => { }); it('handles infinite lists', () => { - const dinfinite: List = cons(infinite)(___(() => dinfinite.run())); + const dinfinite: List = cons(infinite)(y(() => dinfinite)); expect($n(concat(dinfinite)(undef)(_(x => _(_xs => x))))).toBe(0); }); }); diff --git a/test/num.spec.ts b/test/num.spec.ts index 6760a79..d586767 100644 --- a/test/num.spec.ts +++ b/test/num.spec.ts @@ -1,12 +1,12 @@ import { describe, expect, it } from '@jest/globals'; -import { ___, undef } from '../src/core'; +import { undef, y } from '../src/core'; import { toNOrd as $o, NOrd } from '../src/ord'; import { toBoolean as $b, fromBoolean as _b } from '../src/bool'; import { toNumber as $n, Num, Succ, Zero, fromNumber as _n, cmp, div, eq, ge, gt, ifz, le, lt, mod, mul, pred, show, sub, succ, sum } from '../src/num'; import { toString as $s } from '../src/string'; describe('Num', () => { - const infinity: Num = ___(() => Succ(infinity).run()); + const infinity: Num = y(() => Succ(infinity)); describe('toNumber', () => { it('converts 0', () => { diff --git a/test/string.spec.ts b/test/string.spec.ts index 761f8a6..f26c957 100644 --- a/test/string.spec.ts +++ b/test/string.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from '@jest/globals'; -import { _, ___, undef } from '../src/core'; +import { _, undef, y } from '../src/core'; import { NOrd, toNOrd } from '../src/ord'; import { toBoolean as $b } from '../src/bool'; import { toNumber as $n, Zero, gt as ngt } from '../src/num'; @@ -7,7 +7,7 @@ import { toChar as $c, fromChar as _c } from '../src/char'; import { toString as $s, Cons, Empty, String, fromString as _s, append, cmp, empty, eq, ge, gt, le, len, lt, show, wrap } from '../src/string'; describe('String', () => { - const infinite: String = Cons(_c('a'))(___(() => infinite.run())); + const infinite: String = Cons(_c('a'))(y(() => infinite)); describe('toString', () => { it('converts ""', () => {