→
Translation status: हिन्दी reader-locale proof. Term names and code fences follow the hi pack; supporting prose may still be English.
Success return type and recoverable alternate-exit type in function signatures.
Syntax: फलन <name>(<params>) → <type> | फलन <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 `इधरफेंको` and `पकड़ो`.
#
# Common mistakes:
# • Forgetting the ⇥ error type in signatures that use इधरफेंको.
#
# See also: ⇥, फलन, लौटाओ, इधरफेंको, पकड़ो
# =============================================================================
# operatores/function-types — → and ⇥
#
# GRAMMAR:
# funcType :← 'फलन' ident '(' params ')' ('→' type)? ('⇥' type)?
#
# EXPECTED OUTPUT:
# salve, 5, 0
#
# BACKEND:
# Cross-ref फलन/functio.fab and इधरफेंको/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