Type.Spec
Type Specifier DSL.
A language to build type signatures for Primus Lisp primitives.
The signature specifier consists of two parts: the parameter list specifier, and the return value type specifier. They are separated with the @->
operator:
params @-> return
The list of parameters can be specified as a tuple, a variable number of arguments of the same type, or a tuple followed by a variable number of arguments of the same type. Special shortcuts for 1-tuple and 0-tuple are provided.
The return value type could be any
, bool
, byte
, word n
, sym
, int
, or a type variable bound in the parameters list.
Examples:
one int @-> byte;
tuple [int; byte] @-> int;
all a @-> bool;
tuple [sym; int] // all byte @-> bool;
val any : t
any
top type which is inhabitated by all Primus values
val var : string -> t
var x
type variable x
. All variables with the same name in the scope of a definition are unified.
val sym : t
sym
symbol type.
val int : t
a machine integer - a word that has the same width as Arch.addr_size
val bool : t
bool
a one bit word
val byte : t
byte
an eight bit word
val word : int -> t
word n
an n
bit word
val a : t
a
shortcut for var "a"
val b : t
b
shortcut for var "b"
val c : t
c
shortcut for var "c"
val d : t
d
shortcut for var "d"
tuple [args]
specifies that a function accepts a tuple of arguments of specified types.
all t
specifies that a function accepts a variable number of arguments all having type t
.
val unit : [ `Tuple of t list ]
unit
specifies that a function doesn't have any parameters
val (//) : [ `Tuple of t list ] -> [ `All of t ] -> parameters
params // rest
specifies that a function is variadic, but have some number of mandatory arguments, i.e., it accepts a tuple of parameters specified by the params
type specifier and a variadic list of arguments specified by the rest
type specifier.
val (@->) : [< parameters ] -> t -> signature
params @-> t
constructs a signature from the parameter list specifier params
and the return type specifier t