Rex type documentation
Introduction
Rex has a rigid type system and a hierarchical type structure. This document aims to provide a reference about Rex's types for Rex programmers.
Casting between types is provided by the cast library.
Type hierarchy
Types in Rex are hierarchical. The tree below shows the structure of the hierarchy.
- type
- num
- int
- whole
- natural
- whole
- float
- int
- str
- bool
- null
- err
- mathErr
- zeroDivisionErr
- typeErr
- syntaxErr
- scopeErr
- branchErr
- nameErr
- includeErr
- fileErr
- recursionErr
- indexErr
- rangeErr
- mathErr
- num
This hierarchical structure means that, for instance, an int is a subtype of num, and as such, any function which takes parameters of type num can also take parameters of type int - but not the other way around.
Descriptions of types
type- This is the root type from which all other types descend.
num- This is a general numerical type. It is essentially equivalent to
floatat the moment, but may change to accommodate complex numbers in the future. All other numerical types descend fromnum. int- This is an integral numerical type which can represent all integers supported by the system; negative, positive or zero.
whole- This is an integral numerical type which only represents integers which are positive or zero (the whole numbers).
natural- This is an integral numerical type which only represents the positive integers (the natural numbers).
float- This is a numerical type which can represent any floating-point number supported by the system. This means that, in the current implementation of Rex, all numbers which can be represented in Rex can be represented by the
floattype, but this may change in the future so it is its own type. str- This is a string type, for representing strings of characters (text).
bool- This is a Boolean type, for representing
TrueorFalse. null- This is an empty type.
nullrepresents nothing and is useful in cases where a function returns no value.
To do: explain err and its subtypes