A module can access its sub-modules using the regular using or import statements. In fact, a sub-module does not work any differently than an external package, except how it is being referenced.
Perhaps we can recall the example from Chapter 2, Modules, Packages, and Type Concepts. Back then, we created a Calculator module that defines two interest rate-related functions and a Mortgage sub-module that defines a payment calculator function. The Calculator module file has the following source code:
# Calculator.jl
module Calculator
include("Mortgage.jl")
export interest, rate
function interest(amount, rate)
return amount * (1 + rate)
end
function rate(amount, interest)
return interest / amount
end
end # module
Furthermore, the sub-module contains the following code:
# Mortgage.jl
module Mortgage
function payment(amount, rate, years)
# TODO code to calculate monthly payment for the loan
return 100.00
end
end # module
Let's look into how to reference functions and symbols from a sub-module and vice versa.