An import alias binds a shorter name to a module, reducing the noise of repeatedly referencing modules with long hierarchical names. The alias usually takes the module’s final name, so Geometry.Rectangle becomes Rectangle. section 2.3.5
Use aliases to:
- Declare an explicit name with alias Module, as: ShortName. section 2.3.5
- Omit as when the desired name is the module’s final segment. section 2.3.5
- Keep qualified calls such as Rectangle.area(...) while replacing a longer module prefix. section 2.3.5
- Recognize that the compiler resolves the alternate name to the original module and its underlying atom. section 2.4.2 section 2.7.1
Shortening a module reference
defmodule MyModule do alias Geometry.Rectangle def area do Rectangle.area(...) end end The explicit form, alias Geometry.Rectangle, as: Rectangle, has the same effect. section 2.3.5
defmodule MyModule do
alias Geometry.Rectangle, as: Rectangle #1
def my_function do
Rectangle.area(...) #2
end
end
Shows an explicit alias declaration and the shortened module call it enables. section 2.3.5


