Types
Kiki is statically typed. Types can be inferred in most cases, so annotations are not necessary. The whole Kiki doc is typed, including the prose.
Reading types
A type starts with : and always decorates the value rather than the symbol. Hover on a symbol also shows its type:
You can use type-of to check the type of an expression.
Built-in types
Built-in types describe Kiki's scalar values, runtime capabilities, and type values.
Also, :void is for results with no value, :chart for charts, :bytes for raw file contents, :action for a button activation carried in a table column, and :type is the type of types.
Structural types
Here are the collections: list, record, and table.
Function types
Function types list parameter types, a result type, and any effect the function may raise.
:(fn int int -> int !div-by-zero)
Notice that :(fn ..) and :{..} are type expressions, in which types do not need commas.
Type parameters
A single lowercase letter in a type expression is a type parameter. It is similar to templates or for-all in other languages.
:(fn a -> a)
:(fn a -> a) reads "for every type a, a function from type a to the same type." More examples:
:(fn [a] -> bool)
The type parameter gets a concrete type in its use sites:
:int
:decimal
Type classes
Some operations need a capability without requiring one concrete type. Kiki represents these as lightweight built-in type classes.
• num supports numeric arithmetic over int, decimal, and float.
• frac supports division over decimal and float.
• eq supports equality with ==.
• ord supports ordering with <, <=, >, and >=.
• seq is the common sequence interface of strings, lists, and tables. A table is a sequence of records, so length counts its rows and concat appends tables with the same row type; concat of one list joins all of its sequences.
The constraint name replaces the single letter in a displayed type. It still stands for one call-site type, so repeated names preserve relationships just as repeated as do.
Named types
Binding a type gives it a nominal identity.
One-of types
one-of creates a closed set of variants. A variant begins with ' and may carry a typed payload.
:color
:shape
Named variants can be recursive:
:tree
Task and state types
:(Task result) describes deferred work, while :(state value) describes a session-state declaration whose current value has the inner type.
Where next
• doc/effect.ki — errors, optionals, parameters, and effects