Home / Docs / Language guide
Modules and imports
Release v0.4.0
A package with two modules, one importing from the other:
src/shop/prices.una
module shop.prices
pub kind Price = Int in 0..1_000_000
pub kind Item
name: Text
price: Price
--- Private: other modules cannot import it (U1004).
cents(item: Item) -> Int = item.price
pub total(items: List[Item]) -> Int = items.map(each: fn(i) -> cents(i)).sum()src/shop/cart.una
module shop.cart
import shop.prices (Item, total)
pub kind Cart
items: List[Item]
pub cart_total(cart: Cart) -> Int = total(cart.items)- Module path and file path must match (U1008): module
shop.cartlives insrc/shop/cart.una. trusted modulemarks a module allowed to declare policies (§8.5). It must also be listed inuna.toml.- Imports list names explicitly. Kinds, functions, capabilities, handlers, policies and predicates are all imported the same way.
std.testingis the only standard module (§12). - The prelude is imported automatically (§12).
- Visibility: declarations are private unless marked
pub. Using a private declaration from another module is U1004. Import cycles are U1003. - Order: declarations can appear in any order within a module.