Fix linter errors
This commit is contained in:
@@ -28,6 +28,7 @@ export default [
|
|||||||
rules: {
|
rules: {
|
||||||
'arrow-body-style': 'error',
|
'arrow-body-style': 'error',
|
||||||
'no-extra-parens': ['error', 'all'],
|
'no-extra-parens': ['error', 'all'],
|
||||||
|
'no-unexpected-multiline': 'off',
|
||||||
'sort-imports': ['error', { ignoreDeclarationSort: true }],
|
'sort-imports': ['error', { ignoreDeclarationSort: true }],
|
||||||
'@stylistic/quotes': ['error', 'single'],
|
'@stylistic/quotes': ['error', 'single'],
|
||||||
'@stylistic/semi': ['error', 'always'],
|
'@stylistic/semi': ['error', 'always'],
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Num, Zero, ge, ifz, pred, succ } from './num';
|
|||||||
import { x00 } from './byte';
|
import { x00 } from './byte';
|
||||||
import { Char, fromChar as _c, dec as cdec, inc as cinc, eq, ifn } from './char';
|
import { Char, fromChar as _c, dec as cdec, inc as cinc, eq, ifn } from './char';
|
||||||
import { Pair, first, fst, second, snd, uncurry } from './pair';
|
import { Pair, first, fst, second, snd, uncurry } from './pair';
|
||||||
import { List, Nil, cons, head, repeat, set, singleton, tail, update } from './list';
|
import { List, cons, head, repeat, set, singleton, tail, update } from './list';
|
||||||
import { Empty, String, get, len, snoc } from './string';
|
import { Empty, String, get, len, snoc } from './string';
|
||||||
|
|
||||||
type Program = Pair<List<Num>, String>;
|
type Program = Pair<List<Num>, String>;
|
||||||
@@ -57,8 +57,8 @@ const prev: L<(t: State) => State>
|
|||||||
const jump: L<(d: Num) => L<(s: State) => State>>
|
const jump: L<(d: Num) => L<(s: State) => State>>
|
||||||
= _(d => _(s =>
|
= _(d => _(s =>
|
||||||
iif(command(_c('['))(s))(jump(succ(d)))
|
iif(command(_c('['))(s))(jump(succ(d)))
|
||||||
(iif(command(_c(']'))(s))(ifz(pred(d))(cnst(s))(jump(pred(d))))
|
(iif(command(_c(']'))(s))(ifz(pred(d))(cnst(s))(jump(pred(d))))
|
||||||
(jump(d)))(advance(s))));
|
(jump(d)))(advance(s))));
|
||||||
|
|
||||||
const whlnz: L<(t: State) => State>
|
const whlnz: L<(t: State) => State>
|
||||||
= _(s => ifn(read(s))(jump(Zero))(save)(s));
|
= _(s => ifn(read(s))(jump(Zero))(save)(s));
|
||||||
@@ -68,15 +68,15 @@ const endwhl: L<(t: State) => State>
|
|||||||
|
|
||||||
const exec: L<(s: State) => State>
|
const exec: L<(s: State) => State>
|
||||||
= _(s => iif<State>(done(s))(s)(exec(advance
|
= _(s => iif<State>(done(s))(s)(exec(advance
|
||||||
(iif(command(_c('>'))(s))(next)
|
(iif(command(_c('>'))(s))(next)
|
||||||
(iif(command(_c('<'))(s))(prev)
|
(iif(command(_c('<'))(s))(prev)
|
||||||
(iif(command(_c('+'))(s))(inc)
|
(iif(command(_c('+'))(s))(inc)
|
||||||
(iif(command(_c('-'))(s))(dec)
|
(iif(command(_c('-'))(s))(dec)
|
||||||
(iif(command(_c('.'))(s))(output)
|
(iif(command(_c('.'))(s))(output)
|
||||||
(iif(command(_c(','))(s))(input)
|
(iif(command(_c(','))(s))(input)
|
||||||
(iif(command(_c('['))(s))(whlnz)
|
(iif(command(_c('['))(s))(whlnz)
|
||||||
(iif(command(_c(']'))(s))(endwhl)
|
(iif(command(_c(']'))(s))(endwhl)
|
||||||
(id))))))))(s)))));
|
(id))))))))(s)))));
|
||||||
|
|
||||||
export const run: L<(p: String) => L<(i: String) => String>>
|
export const run: L<(p: String) => L<(i: String) => String>>
|
||||||
= _(p => _(i => snd(snd(snd(exec(Pair(Pair(singleton(Zero))(p))(Pair(Pair(Zero)(repeat(x00)))(Pair(i)(Empty)))))))));
|
= _(p => _(i => snd(snd(snd(exec(Pair(Pair(singleton(Zero))(p))(Pair(Pair(Zero)(repeat(x00)))(Pair(i)(Empty)))))))));
|
||||||
|
|||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
export type L<T extends (v: P) => L<any>> = T & { run: () => T; }
|
export type L<T extends (v: P) => L<any>> = T & { run: () => T };
|
||||||
|
|
||||||
export function ___<T extends (v: P) => L<any>>(run: () => T): L<T>{
|
export function ___<T extends (v: P) => L<any>>(run: () => T): L<T> {
|
||||||
const r: T = ((p: Parameters<T>[0]) => {
|
const r: T = ((p: Parameters<T>[0]) => {
|
||||||
let v: any;
|
let v: any;
|
||||||
return ___(() => run()(
|
return ___(() => run()(
|
||||||
___(() => v ??= p.run())
|
___(() => v ??= p.run()),
|
||||||
).run());
|
).run());
|
||||||
}) as T;
|
}) as T;
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -66,11 +66,11 @@ export const cmp: L<<T extends P>(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l:
|
|||||||
= _(<T extends P>(ecmp: L<(l: T) => L<(r: T) => Ord>>) =>
|
= _(<T extends P>(ecmp: L<(l: T) => L<(r: T) => Ord>>) =>
|
||||||
_((l: List<T>) =>
|
_((l: List<T>) =>
|
||||||
_((r: List<T>) => l
|
_((r: List<T>) => l
|
||||||
(r(EQ)(cnst(cnst(LT))))
|
(r(EQ)(cnst(cnst(LT))))
|
||||||
(_(lx => _(lxs => r(GT)(_(rx => _(rxs => iif
|
(_(lx => _(lxs => r(GT)(_(rx => _(rxs => iif
|
||||||
(eqc(EQ)(ecmp(lx)(rx)))
|
(eqc(EQ)(ecmp(lx)(rx)))
|
||||||
(cmp(ecmp)(lxs)(rxs))
|
(cmp(ecmp)(lxs)(rxs))
|
||||||
(ecmp(lx)(rx)))))))))));
|
(ecmp(lx)(rx)))))))))));
|
||||||
|
|
||||||
export const lt: L<<T extends P>(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List<T>) => L<(r: List<T>) => Bool>>>
|
export const lt: L<<T extends P>(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List<T>) => L<(r: List<T>) => Bool>>>
|
||||||
= _(<T extends P>(ecmp: L<(l: T) => L<(r: T) => Ord>>) =>
|
= _(<T extends P>(ecmp: L<(l: T) => L<(r: T) => Ord>>) =>
|
||||||
@@ -88,8 +88,8 @@ export const eq: L<<T extends P>(eeq: L<(l: T) => L <(r: T) => Bool>>) => L<(l:
|
|||||||
= _(<T extends P>(eeq: L<(l: T) => L<(r: T) => Bool>>) =>
|
= _(<T extends P>(eeq: L<(l: T) => L<(r: T) => Bool>>) =>
|
||||||
_((l: List<T>) =>
|
_((l: List<T>) =>
|
||||||
_((r: List<T>) => l
|
_((r: List<T>) => l
|
||||||
(r(True)(cnst(cnst(False))))
|
(r(True)(cnst(cnst(False))))
|
||||||
(_(lx => _(lxs => r(False)(_(rx => _(rxs => and(eeq(lx)(rx))(eq(eeq)(lxs)(rxs)))))))))));
|
(_(lx => _(lxs => r(False)(_(rx => _(rxs => and(eeq(lx)(rx))(eq(eeq)(lxs)(rxs)))))))))));
|
||||||
|
|
||||||
export const ge: L<<T extends P>(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List<T>) => L<(r: List<T>) => Bool>>>
|
export const ge: L<<T extends P>(ecmp: L<(l: T) => L <(r: T) => Ord>>) => L<(l: List<T>) => L<(r: List<T>) => Bool>>>
|
||||||
= _(<T extends P>(ecmp: L<(l: T) => L<(r: T) => Ord>>) =>
|
= _(<T extends P>(ecmp: L<(l: T) => L<(r: T) => Ord>>) =>
|
||||||
|
|||||||
+2
-2
@@ -61,8 +61,8 @@ export const mod: L<(l: Num) => L<(r: Num) => Num>>
|
|||||||
|
|
||||||
export const show: L<(n: Num) => String>
|
export const show: L<(n: Num) => String>
|
||||||
= _(n => iif(lt(n)(fromNumber(10)))
|
= _(n => iif(lt(n)(fromNumber(10)))
|
||||||
(cons(sum(n)(fromNumber(48)))(Empty))
|
(cons(sum(n)(fromNumber(48)))(Empty))
|
||||||
(append(show(div(n)(fromNumber(10))))(show(mod(n)(fromNumber(10))))));
|
(append(show(div(n)(fromNumber(10))))(show(mod(n)(fromNumber(10))))));
|
||||||
|
|
||||||
export const fromNumber: (n: number) => Num
|
export const fromNumber: (n: number) => Num
|
||||||
= n => !n ? Zero : Succ(___(() => fromNumber(n - 1).run()));
|
= n => !n ? Zero : Succ(___(() => fromNumber(n - 1).run()));
|
||||||
|
|||||||
+3
-3
@@ -21,9 +21,9 @@ export const GT: Ord
|
|||||||
|
|
||||||
export const eq: L<(l: Ord) => L<(r: Ord) => Bool>>
|
export const eq: L<(l: Ord) => L<(r: Ord) => Bool>>
|
||||||
= _(l => _(r => l
|
= _(l => _(r => l
|
||||||
(r(True)(False)(False))
|
(r(True)(False)(False))
|
||||||
(r(False)(True)(False))
|
(r(False)(True)(False))
|
||||||
(r(False)(False)(True))));
|
(r(False)(False)(True))));
|
||||||
|
|
||||||
export const show: L<(o: Ord) => String>
|
export const show: L<(o: Ord) => String>
|
||||||
= _(o => o(_s('LT'))(_s('EQ'))(_s('GT')));
|
= _(o => o(_s('LT'))(_s('EQ'))(_s('GT')));
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@ import { Ord } from './ord';
|
|||||||
import { Bool } from './bool';
|
import { Bool } from './bool';
|
||||||
import { fromNumber as _nn } from './num';
|
import { fromNumber as _nn } from './num';
|
||||||
import { toChar as $c, Char, fromChar as _c, cmp as cmpc, eq as eqc } from './char';
|
import { toChar as $c, Char, fromChar as _c, cmp as cmpc, eq as eqc } from './char';
|
||||||
import { Cons, List, Nil, append, cmp as cmpl, concat, cons, eq as eql, ge as gel, gt as gtl, le as lel, lt as ltl } from './list';
|
import { Cons, List, Nil, append, cmp as cmpl, eq as eql, ge as gel, gt as gtl, le as lel, lt as ltl } from './list';
|
||||||
|
|
||||||
export type String = List<Char>;
|
export type String = List<Char>;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ export const ge: L<(l: String) => L<(r: String) => Bool>>
|
|||||||
export const gt: L<(l: String) => L<(r: String) => Bool>>
|
export const gt: L<(l: String) => L<(r: String) => Bool>>
|
||||||
= gtl(cmpc);
|
= gtl(cmpc);
|
||||||
|
|
||||||
export const wrap: L<(w: String) => L<(c: String) => String>>
|
export const wrap: L<(w: String) => L<(c: String) => String>>
|
||||||
= _(w => _(c => append(w)(append(c)(w))));
|
= _(w => _(c => append(w)(append(c)(w))));
|
||||||
|
|
||||||
export const fromString: (xs: string) => String
|
export const fromString: (xs: string) => String
|
||||||
|
|||||||
+2
-2
@@ -40,8 +40,8 @@ describe('BF', () => {
|
|||||||
|
|
||||||
it('prints "Hello World!"', () => {
|
it('prints "Hello World!"', () => {
|
||||||
expect($s(run
|
expect($s(run
|
||||||
(_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'))
|
(_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'))
|
||||||
(_s(''))))
|
(_s(''))))
|
||||||
.toBe('Hello World!\n');
|
.toBe('Hello World!\n');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-6
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from '@jest/globals';
|
import { describe, expect, it } from '@jest/globals';
|
||||||
import { toNative as $$, L, _, fromNative as __, ___, undef } from '../src/core';
|
import { toNative as $$, _, fromNative as __, ___, undef } from '../src/core';
|
||||||
import { toNOrd as $o, NOrd } from '../src/ord';
|
import { toNOrd as $o, NOrd } from '../src/ord';
|
||||||
import { toBoolean as $b, iif } from '../src/bool';
|
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';
|
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';
|
||||||
@@ -261,9 +261,9 @@ describe('List', () => {
|
|||||||
it('handles infinite lists', () => {
|
it('handles infinite lists', () => {
|
||||||
expect($n(
|
expect($n(
|
||||||
foldr
|
foldr
|
||||||
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
||||||
(Zero)
|
(Zero)
|
||||||
(infinite)))
|
(infinite)))
|
||||||
.toBe(15);
|
.toBe(15);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -284,8 +284,8 @@ describe('List', () => {
|
|||||||
it.failing('handles infinite lists', () => {
|
it.failing('handles infinite lists', () => {
|
||||||
expect($n(
|
expect($n(
|
||||||
foldrz
|
foldrz
|
||||||
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
||||||
(infinite)))
|
(infinite)))
|
||||||
.toBe(15);
|
.toBe(15);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from '@jest/globals';
|
import { describe, expect, it } from '@jest/globals';
|
||||||
import { ___, L, undef } from '../src/core';
|
import { ___, undef } from '../src/core';
|
||||||
import { toNOrd as $o, NOrd } from '../src/ord';
|
import { toNOrd as $o, NOrd } from '../src/ord';
|
||||||
import { toBoolean as $b, fromBoolean as _b } from '../src/bool';
|
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 { 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';
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from '@jest/globals';
|
import { describe, expect, it } from '@jest/globals';
|
||||||
import { L, _, ___, undef } from '../src/core';
|
import { _, ___, undef } from '../src/core';
|
||||||
import { NOrd, toNOrd } from '../src/ord';
|
import { NOrd, toNOrd } from '../src/ord';
|
||||||
import { toBoolean as $b } from '../src/bool';
|
import { toBoolean as $b } from '../src/bool';
|
||||||
import { toNumber as $n, Zero, gt as ngt } from '../src/num';
|
import { toNumber as $n, Zero, gt as ngt } from '../src/num';
|
||||||
@@ -37,7 +37,7 @@ describe('String', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('repeat', () => {
|
// describe('repeat', () => {
|
||||||
// it('repeat "a" is "aaa..."', () => {
|
// it('repeat "a" is "aaa..."', () => {
|
||||||
// expect($na(
|
// expect($na(
|
||||||
// repeat(_s('a'))<String>(_((x0: Char) => _((x1s: String) =>
|
// repeat(_s('a'))<String>(_((x0: Char) => _((x1s: String) =>
|
||||||
@@ -55,7 +55,6 @@ describe('String', () => {
|
|||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
|
||||||
describe('empty', () => {
|
describe('empty', () => {
|
||||||
it('empty "" is True', () => {
|
it('empty "" is True', () => {
|
||||||
expect($b(empty(_s('')))).toEqual(true);
|
expect($b(empty(_s('')))).toEqual(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user