Declare implementations and dependencies via standard interfaces for operations (#8)

Adds a new subdirectory `interfaces` where standard interfaces
  are defined. Additional interfaces for a given operation can
  be added with an `AliasOf` type operator. Provides type
  operators that give the return type, full function type, and
  the type of a dependency on, a given operator.

  Resolves #6.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
Reviewed-on: #8
This commit is contained in:
Glen Whitney 2023-01-22 01:34:57 +00:00
parent 3fa216d1f4
commit cc1e66c054
24 changed files with 397 additions and 72 deletions

View file

@ -1,7 +1,25 @@
import type { Signature } from '../interfaces/type.js'
export const number_type = {
before: ['Complex'],
test: (n: unknown): n is number => typeof n === 'number',
from: {string: s => +s}
from: { string: (s: string) => +s }
}
export const zero = (a: number) => 0
declare module "../interfaces/type" {
interface AssociatedTypes<T> {
numbers: {
type: number
zero: 0
one: 1
nan: typeof NaN
real: number
}
}
}
// I don't like the redundancy of repeating 'zero'; any way to eliminate that?
export const zero: Signature<'zero', number> = (a) => 0
export const one: Signature<'one', number> = (a) => 1
export const nan: Signature<'nan', number> = (a) => NaN
export const re: Signature<'re', number> = (a) => a