Modules
Modules organize code into namespaces.
Definition
module Network {
function connect(): None {
println("Connecting...");
return None;
}
}
Usage
Functions inside a module can be accessed using dot notation.
The compiler lowers Module.function() to an internal mangled symbol Module__function.
result: Integer = Math.square(5);
You can also alias imports:
import std.math as math;
import std.io as io;
value: Integer = math.abs(-5);
io.println("{value}");
Aliases also work for typed function values:
import std.math as math;
f: (Integer) -> Integer = math.abs;
Builtin free functions with no import requirement can be used the same way:
make: (Integer, Integer) -> Range<Integer> = range;
check: (Integer, Integer) -> None = assert_eq;
stop: (Integer) -> None = exit;
The same also applies to direct stdlib object members:
cwd: () -> String = System.cwd;
now_unix: () -> Integer = Time.unix;
rand: () -> Float = Math.random;
Backward compatibility: direct Module__function() calls are still accepted.