Typically, packages consist of one or more modules. As packages grow, it may be useful to organize the main module of the package into smaller modules. A common idiom is to define those modules as submodules of the main module:
module RootModule
module SubModule1
...
end
module SubModule2
...
end
end
Initially, neither root module nor submodules have access to each others' exported symbols. However, relative imports are supported to address this issue:
module RootModule
module SubModule1
const x = 10
export x
end
module SubModule2
# import submodule of parent module
using ..SubModule1
const y = 2x
export y
end
# import submodule of current module
using .SubModule1
using .SubModule2
const z = x + y
end
In this example, the value of RootModule.z
is 30
.