Modules
A file is a module. Its declarations are private unless marked pub:
type Point = { Int x; Int y; };
pub Int dist2(Point a, Point b) { Int dx = a.x - b.x; Int dy = a.y - b.y; return dx * dx + dy * dy;}Import it by path, relative to the importing file:
import "geometry.resid"; // every pub nameimport "geometry.resid" (dist2); // only theseimport "geometry.resid" as G; // qualified: G.dist2(a, b)Each module keeps its own names. If two modules you import both export a
parse, import them as and qualify the use: json.parse(s),
toml.parse(s). A plain parse(s) would be ambiguous and is an error
(E0223); a function of your own named parse wins over both.
An import that is not found beside the importing file is looked up in the
standard library (lib/ of the Resid installation), so
import "crypto.resid"; works anywhere. A missing module is an error
(E0221).
An import can also be attenuated: the module and everything it imports run with at most the listed capabilities, even if it asks for more:
import "http.resid" @requires(network);See Capabilities and Modules in the reference.
