Vikari Language Documentation


Available since:  v0.4.0.

Type Labels

Type labels are an optional component of anywhere a variable is declared. Beginning with a : and followed by a type name (a capitalized Vikari identifier, and then followed by a sequence of uppercase letters, lowercase letters, numbers, or underscores), type labels provide type hints to the interpreter to provide additional type checking for statements, functions, and type declarations. Presently the only implemented Vikari language feature that supports type labels are variable declaration statements.

If a type label is elided, the variable automatically has a declared type of AtonementCrystal. Vikari also tracks the assigned type, which is simply the type of the initializer expression or the result of the last assignment statement to the variable.

Examples

The following demonstrates proper use of type labels in variable declaration statements.

~:Declaring variables of the default type.:~
foo << null                  ~:Has type AtonementCrystal.:~
bar:AtonementCrystal << null ~:Also has type AtonementCrystal.:~

~:Assignment is allowed to subtypes of the type label.:~
v1:AtonementCrystal << 1
v2:Value << 2
v3:Number << 3
v4:Integer << 4

~:Assignment of an incorrect type is not allowed.:~
int:Integer << true ~:Syntax error!:~
bool:Boolean << 5   ~:Syntax error!:~