/taxon

A concise type system for documenting Javascript APIs.

taxon

taxon is a concise type system for annotating and documenting Javascript APIs.

Basics

Primitives

any ('a' | 5 | [])
int (123)
real (3.0234)
bool (true)
string ('hello')
none (undefined)
void (undefined)
null (null)
nan (NaN)

Builtins

Array<Type>: [...values: Type]
Shallow<Type>: { ...properties: Type }
Monad<Type>: (arg: Type) => Type
Maybe<Type>: Type | none
Tuple<A, B, ..., Z>: [A, B, ..., Z]
Of<A, B, ..., Z>: A | B | ... | Z

Definition

Integer: int

Validation

'x' :: string // true
5.6 :: int // false
undefined :: Maybe<bool> // true
true :: Maybe<bool> // true
3 :: Maybe<bool> // false

Application

[Class.myMethod]: Function
[Class.instance]: Data
[Class
	[myMethod]: Function
	[instance]: Data
]

Rules

Functions

Adder: (augend: int, addend: int) => int

Optional Arguments

Alert: (message: string, [type: string]) => void

Default Arguments

Alert: (message: string, type = 'default': string) => void

Objects

Human: { height: int, weight: int }
FunctionMap: { ...functions: Function }

Templating

Accumulator<Type, Modifier>: (acc: Type, mod: Modifier) => Type

Algebraics

Computable: int | real
Leaf: int
Branch: { value: int, ...leaves: Maybe<Node> }
Node: Branch | Leaf

Composition

Property

Human: { height, weight: int }
Human: { (height, weight): int }

Algebraic

Leaf<Value>: Value
Branch<Value>: { value: Value, (left, right): Maybe<Leaf<Value>> }
Node: Branch | Leaf
Heap: Node<int>
Thunk<Value>: Monad<Value> | Value

Algebraics cannot be used directly as applications.

Substitution

Animal: { weight: int }
Dog: { #Animal, color: string }
[View]: (element: HTMLElement) => View
[Model]: (model: Shallow<Function>) => Model
[ViewModel]: (#View, #Model) => Construct