Skip to main content

Types

Mux uses strict static typing with NO implicit type conversions. All type conversions must be explicit using conversion methods.

Primitive Types

primitive_types.mux
Loading...

Type Conversions

Numeric Conversions

numeric_conversions.mux
Loading...

String Length

length() counts code points, not bytes - the same unit char denotes, so a string behaves as a sequence of char.

string_length.mux
Loading...

A code point outside ASCII still counts as one, even though it occupies several bytes in memory.

Note that a code point is not always a whole visible glyph. A character built from a base letter plus a combining mark, or an emoji assembled from several code points, counts once per code point rather than once per glyph - so length() answers "how many char values", which is what indexing and slicing also use, rather than "how many symbols a reader sees".

String Parsing (Fallible Conversions)

String and char parsing methods return result<T, string> because they can fail:

string_parsing.mux
Loading...

No Implicit Conversions

The following operations are compile-time errors:

implicit_conversions.mux
Loading...

Conversion Methods Reference

From TypeMethodReturnsNotes
int.to_string()stringConverts to string representation
int.to_float()floatConverts to floating-point
int.to_int()intIdentity function
float.to_string()stringConverts to string representation
float.to_int()intTruncates decimal part
float.to_float()floatIdentity function
bool.to_string()stringReturns "true" or "false"
bool.to_int()intReturns 1 or 0
bool.to_float()floatReturns 1.0 or 0.0
char.to_string()stringConverts char to string
char.to_int()result<int, string>Digit value for '0'-'9' only
string.to_string()stringIdentity function
string.to_int()result<int, string>Parses string as integer
string.to_float()result<float, string>Parses string as float

Composite Types

These are type forms rather than runnable declarations - T, K, V and U stand for whatever you instantiate them with:

FormMeaning
optional<T>a value that may or may not exist
result<T, E>success carrying T, or an error carrying E
list<T>ordered collection
map<K, V>key-value pairs, iterating in insertion order
set<T>unique elements, iterating in insertion order
tuple<T, U>fixed-size pair
composite_types.mux
Loading...

Tuples

Tuples are fixed size pairs. A tuple always has exactly two elements.

tuple_basics.mux
Loading...

Tuples also support to_string() and a default constructor:

tuple_default.mux
Loading...

References

Mux supports references for safe memory access:

references.mux
Loading...

Reference Syntax:

  • Create reference: &variable or &expression
  • Dereference: *reference (required for both reading and writing)
  • Pass to functions: func(&int ref) declares parameter, update(&x) passes reference
  • References to references: Not supported

See Also