functions
Functions
Typing functions
Functions in Typed R can explicitly declare:
- the type of each parameter,
- the return type.
Typed function signatures act as clear contracts, improving readability and tooling support, and enabling early error detection.
Higher-order functions
Typed R fully supports higher-order functions, meaning functions can:
- be passed as arguments,
- be returned as values.
The type system tracks function types, ensuring that function composition and callbacks are used correctly.
Closures and lambdas
Typed R supports:
- anonymous functions (lambdas) for concise functional programming,
- closures, where functions capture variables from their surrounding environment.
The type system ensures that captured variables and returned functions remain type-safe, even in advanced functional patterns.