Type signatures. Provides basic facilities for declaring data types for vars, function arguments and return values.

Type signatures can be used for any object which can have metadata, and are stored in object’s metadata under :tsig key. In addition, type signatures can be used in binding/arg vectors of let, fn and loop.

Special syntax sugar :- for type signatures is also available. If possible, host type hints are generated automatically from type signatures, so that user does not have to specify types twice.

Following macros recognize type signatures, support sugared syntax and generate type hints: def, defonce, defn, defnonce, deftype, defrecord and defprotocol (in methods).

Following macros recognize sugared syntax and generate type hints, but do not store type signatures in metadata: fn, let, if-let, when-let, loop, iloop. For these cases, type checking library must get type signatures from static analysis of source files.

dunaj.type API is a very early experiment with incomplete functionality. Expect rough edges.
Dunaj does not include type checking facilities, as these are left to third party libraries, which can utilize and extend type signatures defined here.
Notes
  • [x y z …​] denotes any collection, items of which must satisfy type signatures x y z …​ If no special modifiers (e.g. required) are used, items are optional and collection may even be empty or nil.

  • {k1 v1, k2 v2, …​} denotes collection transformable to the sequence of key-value pairs that satisfy type signatures k1 v1, k2 v2, …​ If no special modifiers are used, keys are optional and collection may even be empty or nil. Values for optional key may also be nil, even if this is not indicated in the value signature.

  • [] is equivalent to (Maybe dunaj.coll/IRed)

  • {} is equivalent to (Maybe dunaj.coll/IPersistentMap)

  • #{} is equivalent to (Maybe dunaj.coll/IPersistentSet)

Any

Available since version 1.0 (view source)

VAR of type AnySignature

A type signature representing any type.

Fn

Available since version 1.0 (view source)

Usage:
  • (Fn & msigs)

Returns a type signature for an invocable object, having msigs as type signatures for its invoke methods.

Return types are first items in signature vectors!

Hinted

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (Hinted sig hinting-sig)

Type signature:
  • (Signature ⨯ Signature) → Signature

Returns type signature equivalent to sig that returns type hint from hinting-sig as its host type hints.

I

Available since version 1.0 (view source)

Usage:
  • (I & sigs)

Type signature:
  • ((Va Signature)) → Signature

Returns a type signature for intersection of signatures sigs.

KeywordMap

Available since version 1.0 (view source)

VAR of type Signature

A type signature for map where keys are keywords.

Macro

Available since version 1.0 (view source)

VAR of type Signature

A placeholder indicating that var holds a macro and that the type signature is not missing. Is used mainly in defalias constructs.

Maybe

Available since version 1.0 (view source)

Usage:
  • (Maybe sig)

Type signature:
  • (Signature) → Signature

Returns a type signature that represents either nil or object satisfying type signature sig.

NotHinted

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (NotHinted sig)

Type signature:
  • (Signature) → Signature

Returns type signature equivalent to sig that does not provide type hints.

Assumes nil type signature will never have type hint.

NotPrimitive

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (NotPrimitive sig)

Type signature:
  • (Signature) → Signature

Returns type signature equivalent to sig that does not provide primitive type hints.

Predicate

Available since version 1.0 (view source)

VAR of type Signature

A type signature for one-argument predicate.

R

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (R & protocols)

Type signature:
  • ((Va Signature)) → Signature

Returns a type signature for record implementing protocols.

Range

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (Range sig from)

  • (Range sig from to)

Type signatures:
  • (Signature ⨯ Any) → Signature

  • (Signature ⨯ Any ⨯ Any) → Signature

Returns a type signature with given constraints

Required

Available since version 1.0 (view source)

Usage:
  • (Required sig)

Type signature:
  • (Signature) → Signature

Returns required type signature equivalent to sig.

Signature

Available since version 1.0 (view source)

not referred automatically

VAR of type Unknown

A type signature for type signatures. :)

TypeHint

Available since version 1.0 (view source)

not referred automatically

VAR of type Signature

A type signature for host type hints.

U

Available since version 1.0 (view source)

Usage:
  • (U & sigs)

Type signature:
  • ((Va Signature)) → Signature

Returns a type signature for union of signatures sigs.

Unknown

Available since version 1.0 (view source)

not referred automatically

VAR of type UnknownSignature

A type signature representing unknown type.

Va

Available since version 1.0 (view source)

Usage:
  • (Va sig)

Type signature:
  • (Signature) → Signature

Returns a type signature for homogeneous variable part of variadic function arguments, with sig representing type signature of its items.