→
Translation status: English reader-locale proof. Code fences render through the en pipeline; prose is canonical Latin.
Success return type and recoverable alternate-exit type in function signatures.
Syntax: functio <name>(<params>) → <type> | functio <name>(<params>) → <success> ⇥ <error>
Category#
function
Related#
Examples#
radix/corpus/operatores/function-types.fab (canonical · operator-group)#
Success return type and recoverable alternate-exit type in function signatures.
# =============================================================================
# → — Success return type and recoverable alternate-exit type in function signatures.
# =============================================================================
#
# What this teaches:
# • Return type annotation — `→` separates a function signature from its success return type.
# • Fallible return — `⇥` after `→` declares a recoverable error type, paired with `iace` and `cape`.
#
# Common mistakes:
# • Forgetting the ⇥ error type in signatures that use iace.
#
# See also: ⇥, functio, redde, iace, cape
# =============================================================================
# operatores/function-types — → and ⇥
#
# GRAMMAR:
# funcType :← 'functio' ident '(' params ')' ('→' type)? ('⇥' type)?
#
# EXPECTED OUTPUT:
# salve, 5, 0
#
# BACKEND:
# Cross-ref functio/functio.fab and iace/functio-fallibilis.fab.
fn saluta() → string {
return "salve"
}
fn divide(int a, int b) → int ⇥ string {
if b ≡ 0 then throw "division by zero"
return a / b
}
fn tutum(int a, int b) → int {
do {
return divide(a, b)
}
catch err {
warn err
return 0
}
}
main {
print saluta()
print tutum(10, 2)
print tutum(10, 0)
}Expected output:
salve
5
0