Skip to main content
Version: Next

Nesting

Namespaces can be nested, which means that we can define a namespace inside another namespace. As an illustration, let us define a variant of Euro in which the constants are all grouped inside using a sub-namespace.

namespace Euro {
export type t = nat;
export let add = (a: t, b: t): t => a + b;
export namespace Coin {
export let one: t = 1n;
export let two: t = 2n;
};
};

To access nested namespaces we simply apply the selection operator more than once:

type storage = Euro.t;
const increment = (s: storage) : storage =>
Euro.add (s, Euro.Coin.one);

Note that the sub-namespace Coin had to be prefixed by the keyword export to enable access to its contents.