Fix linter errors
This commit is contained in:
@@ -28,6 +28,7 @@ export default [
|
||||
rules: {
|
||||
'arrow-body-style': 'error',
|
||||
'no-extra-parens': ['error', 'all'],
|
||||
'no-unexpected-multiline': 'off',
|
||||
'sort-imports': ['error', { ignoreDeclarationSort: true }],
|
||||
'@stylistic/quotes': ['error', 'single'],
|
||||
'@stylistic/semi': ['error', 'always'],
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Num, Zero, ge, ifz, pred, succ } from './num';
|
||||
import { x00 } from './byte';
|
||||
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 { 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';
|
||||
|
||||
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>>
|
||||
= _(d => _(s =>
|
||||
iif(command(_c('['))(s))(jump(succ(d)))
|
||||
(iif(command(_c(']'))(s))(ifz(pred(d))(cnst(s))(jump(pred(d))))
|
||||
(jump(d)))(advance(s))));
|
||||
(iif(command(_c(']'))(s))(ifz(pred(d))(cnst(s))(jump(pred(d))))
|
||||
(jump(d)))(advance(s))));
|
||||
|
||||
const whlnz: L<(t: State) => State>
|
||||
= _(s => ifn(read(s))(jump(Zero))(save)(s));
|
||||
@@ -68,15 +68,15 @@ const endwhl: L<(t: State) => State>
|
||||
|
||||
const exec: L<(s: State) => State>
|
||||
= _(s => iif<State>(done(s))(s)(exec(advance
|
||||
(iif(command(_c('>'))(s))(next)
|
||||
(iif(command(_c('<'))(s))(prev)
|
||||
(iif(command(_c('+'))(s))(inc)
|
||||
(iif(command(_c('-'))(s))(dec)
|
||||
(iif(command(_c('.'))(s))(output)
|
||||
(iif(command(_c(','))(s))(input)
|
||||
(iif(command(_c('['))(s))(whlnz)
|
||||
(iif(command(_c(']'))(s))(endwhl)
|
||||
(id))))))))(s)))));
|
||||
(iif(command(_c('>'))(s))(next)
|
||||
(iif(command(_c('<'))(s))(prev)
|
||||
(iif(command(_c('+'))(s))(inc)
|
||||
(iif(command(_c('-'))(s))(dec)
|
||||
(iif(command(_c('.'))(s))(output)
|
||||
(iif(command(_c(','))(s))(input)
|
||||
(iif(command(_c('['))(s))(whlnz)
|
||||
(iif(command(_c(']'))(s))(endwhl)
|
||||
(id))))))))(s)))));
|
||||
|
||||
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)))))))));
|
||||
|
||||
+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]) => {
|
||||
let v: any;
|
||||
return ___(() => run()(
|
||||
___(() => v ??= p.run())
|
||||
___(() => v ??= p.run()),
|
||||
).run());
|
||||
}) 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>>) =>
|
||||
_((l: List<T>) =>
|
||||
_((r: List<T>) => l
|
||||
(r(EQ)(cnst(cnst(LT))))
|
||||
(_(lx => _(lxs => r(GT)(_(rx => _(rxs => iif
|
||||
(eqc(EQ)(ecmp(lx)(rx)))
|
||||
(cmp(ecmp)(lxs)(rxs))
|
||||
(ecmp(lx)(rx)))))))))));
|
||||
(r(EQ)(cnst(cnst(LT))))
|
||||
(_(lx => _(lxs => r(GT)(_(rx => _(rxs => iif
|
||||
(eqc(EQ)(ecmp(lx)(rx)))
|
||||
(cmp(ecmp)(lxs)(rxs))
|
||||
(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>>>
|
||||
= _(<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>>) =>
|
||||
_((l: List<T>) =>
|
||||
_((r: List<T>) => l
|
||||
(r(True)(cnst(cnst(False))))
|
||||
(_(lx => _(lxs => r(False)(_(rx => _(rxs => and(eeq(lx)(rx))(eq(eeq)(lxs)(rxs)))))))))));
|
||||
(r(True)(cnst(cnst(False))))
|
||||
(_(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>>>
|
||||
= _(<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>
|
||||
= _(n => iif(lt(n)(fromNumber(10)))
|
||||
(cons(sum(n)(fromNumber(48)))(Empty))
|
||||
(append(show(div(n)(fromNumber(10))))(show(mod(n)(fromNumber(10))))));
|
||||
(cons(sum(n)(fromNumber(48)))(Empty))
|
||||
(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()));
|
||||
|
||||
+3
-3
@@ -21,9 +21,9 @@ export const GT: Ord
|
||||
|
||||
export const eq: L<(l: Ord) => L<(r: Ord) => Bool>>
|
||||
= _(l => _(r => l
|
||||
(r(True)(False)(False))
|
||||
(r(False)(True)(False))
|
||||
(r(False)(False)(True))));
|
||||
(r(True)(False)(False))
|
||||
(r(False)(True)(False))
|
||||
(r(False)(False)(True))));
|
||||
|
||||
export const show: L<(o: Ord) => String>
|
||||
= _(o => o(_s('LT'))(_s('EQ'))(_s('GT')));
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { Ord } from './ord';
|
||||
import { Bool } from './bool';
|
||||
import { fromNumber as _nn } from './num';
|
||||
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>;
|
||||
|
||||
@@ -27,7 +27,7 @@ export const ge: L<(l: String) => L<(r: String) => Bool>>
|
||||
export const gt: L<(l: String) => L<(r: String) => Bool>>
|
||||
= 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))));
|
||||
|
||||
export const fromString: (xs: string) => String
|
||||
|
||||
+2
-2
@@ -40,8 +40,8 @@ describe('BF', () => {
|
||||
|
||||
it('prints "Hello World!"', () => {
|
||||
expect($s(run
|
||||
(_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'))
|
||||
(_s(''))))
|
||||
(_s('++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'))
|
||||
(_s(''))))
|
||||
.toBe('Hello World!\n');
|
||||
});
|
||||
});
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
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 { 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';
|
||||
@@ -261,9 +261,9 @@ describe('List', () => {
|
||||
it('handles infinite lists', () => {
|
||||
expect($n(
|
||||
foldr
|
||||
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
||||
(Zero)
|
||||
(infinite)))
|
||||
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
||||
(Zero)
|
||||
(infinite)))
|
||||
.toBe(15);
|
||||
});
|
||||
});
|
||||
@@ -284,8 +284,8 @@ describe('List', () => {
|
||||
it.failing('handles infinite lists', () => {
|
||||
expect($n(
|
||||
foldrz
|
||||
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
||||
(infinite)))
|
||||
(_(x => _(a => sum(x)(iif(eqn(_n(5))(x))(Zero)(a)))))
|
||||
(infinite)))
|
||||
.toBe(15);
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
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 { 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';
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
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 { toBoolean as $b } from '../src/bool';
|
||||
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..."', () => {
|
||||
// expect($na(
|
||||
// repeat(_s('a'))<String>(_((x0: Char) => _((x1s: String) =>
|
||||
@@ -55,7 +55,6 @@ describe('String', () => {
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
describe('empty', () => {
|
||||
it('empty "" is True', () => {
|
||||
expect($b(empty(_s('')))).toEqual(true);
|
||||
|
||||
Reference in New Issue
Block a user