diff --git a/package.json5 b/package.json5 index c27ab64..0d15af2 100644 --- a/package.json5 +++ b/package.json5 @@ -7,7 +7,7 @@ test: 'echo "Error: no test specified" && exit 1', build: 'mkdirp build && cpy etc/package.json build --flat && tsc', start: 'node build', - go: 'pnpm --sequential "/clean|build|start/"', + go: 'pnpm clean && pnpm build && pnpm start', clean: 'del-cli build', }, packageManager: 'pnpm', diff --git a/src/Complex/arithmetic.ts b/src/Complex/arithmetic.ts index 5776cd6..4f78bb5 100644 --- a/src/Complex/arithmetic.ts +++ b/src/Complex/arithmetic.ts @@ -2,7 +2,7 @@ import {Complex} from './type.js' import type { Dependencies, Signature, Returns, RealType, AliasOf } from '../interfaces/type.js' -import {$implement} from '../interfaces/type.js' +import {$reflect} from '../interfaces/type.js' declare module "../interfaces/type" { interface Signatures { @@ -74,7 +74,7 @@ export const divide = // and we have to get it straight which operations we need on each type, and // in fact, we need `addReal` on both T and Complex, hence the dependency // with a custom name, not generated via Dependencies<...> -$implement!('sqrt', +export const sqrt = $reflect!('sqrt', (dep: Dependencies<'equal' | 'conservativeSqrt' | 'unaryMinus', RealType> & Dependencies<'zero' | 'complex', T> & Dependencies<'absquare' | 're' | 'divideReal', Complex> diff --git a/src/generic/arithmetic.ts b/src/generic/arithmetic.ts index 3903b8d..de5b608 100644 --- a/src/generic/arithmetic.ts +++ b/src/generic/arithmetic.ts @@ -1,7 +1,7 @@ import type {Dependencies, Signature} from '../interfaces/type.js' -import {$implement} from '../interfaces/type.js' +import {$reflect} from '../interfaces/type.js' -$implement!('square', +export const square = $reflect!('square', (dep: Dependencies<'multiply', T>) => (z:T) => dep.multiply(z, z)) // z => dep.fooBar(z, z) // fails as desired // z => dep.multiply(z, 'foo') // still fails as desired diff --git a/src/interfaces/type.ts b/src/interfaces/type.ts index 75d1b4c..2b38374 100644 --- a/src/interfaces/type.ts +++ b/src/interfaces/type.ts @@ -82,7 +82,8 @@ export type Dependencies, T> = Deps<{[K in Name]: S export type AliasOf = T & {aliasOf?: Name} // For defining implementations with type reflection -export function $implement(name: string, expr: Impl) { - $$define!(name, expr, false, true); // Final `true` is export +export function $reflect(name: string, expr: Impl) : Impl & { reflectedType: string} { + $$define!(name, expr, false, false); $$ident!(name).reflectedType = $$typeToString!(true, false, true); + return $$ident!(name) } diff --git a/src/numbers/arithmetic.ts b/src/numbers/arithmetic.ts index d2d3414..4b4d2cb 100644 --- a/src/numbers/arithmetic.ts +++ b/src/numbers/arithmetic.ts @@ -1,6 +1,6 @@ import type {configDependency} from '../core/Config.js' import type {Dependencies, Signature} from '../interfaces/type.js' -import { $implement } from '../interfaces/type.js' +import { $reflect } from '../interfaces/type.js' export const add: Signature<'add', number> = (a, b) => a + b export const unaryMinus: Signature<'unaryMinus', number> = a => -a @@ -11,10 +11,10 @@ export const absquare: Signature<'absquare', number> = a => a * a export const reciprocal: Signature<'reciprocal', number> = a => 1 / a export const divide: Signature<'divide', number> = (a, b) => a / b -const basicSqrt = a => isNaN(a) ? NaN : Math.sqrt(a) +const basicSqrt = (a: number) => isNaN(a) ? NaN : Math.sqrt(a) export const conservativeSqrt: Signature<'conservativeSqrt', number> = basicSqrt -$implement!('sqrt', +export const sqrt = $reflect!('sqrt', (dep: configDependency & Dependencies<'complex', number>): Signature<'sqrt', number> => { if (dep.config.predictable || !dep.complex) { return basicSqrt