Modules
Gleam code is organized into units called modules. A module is a
bunch of definitions (of types, functions, etc.) that seem to belong together.
For example, the
gleam/io
module contains a variety of functions for printing, like
println
.
All gleam code is in some module or other, whose name comes from the
name of the file it's in. For example,
gleam/io
is in a file called io.gleam
in a directory called gleam
.
For code in one module to access code in another module, we import it using
the import
keyword, and the name used to refer to it is the last
part of the module name. For example, the
gleam/io
module is referred to as io
once imported.
The as
keyword can be used to refer to a module by a different
name. See how the
gleam/string
module is referred to as text
here.