Functions and closures in Edva are first-class values with uniform 16-byte representation and full static type inference.
13.1 Signatures, types, and runtime ABI
Aspect
Syntax / Representation
Rules & Diagnostics
Multi-arg signature
f: Int, String => <>
Declared on the line preceding f = a, b => body (E2009 if combined inline)
Zero-arg signature
f: () => Int
Defined with f = !=> body and invoked with postfix f! (f() is rejected, E2086)
Void return signature
f: String => ()
Returns Unit (void in LLVM IR)
Nested function type
#type Cb (Int => Int) apply: (Int => Int), Int => Int
Wrap function types in parentheses (...) when inside records, containers, or parameter lists
Runtime representation
{ ptr fn_ptr, ptr env_ptr } (16 bytes)
fn_ptr: machine code pointer; env_ptr: arena-allocated capture struct pointer (null for non-capturing functions). Zero RTTI or vtables
13.2 Function definition forms
Form
Syntax Example
Parameter Binding & Semantics
Diagnostic
Explicit parameter fn
add = a, b => a + b
Bare comma-separated names before => (single-param (a) => is forbidden, E2037)
E2040: explicit _ =>
Destructuring parameter fn
sum_pt = (x, y) => x + y add_p = (a, b), (c, d) => (a + c, b + d)
Positional (a, b) or named (x, y) / (x = lx, y = ly) tuple or record destructuring per parameter
E2037: single-param (x) =>
Nullary function
tick = !=> count = count + 1
0-parameter function; called via tick!
E2086: tick() forbidden
Grouped implicit lambda
(_ * 2), (10 - _), ((a = _, b = 1))
Innermost (...) group with free _ becomes a 1-arg function
—
Partial application
sub(_, 5), sub(100, _), sub(a = _, b = 2)
A call with _ as a direct (positional or name = _) argument, in a call-argument or [predicate] guard position where _ is not otherwise bound, is the closure _ => sub(_, 5) (apply(sub(_, 5), 20), k [gt(_, 5)] "big" \| "small"). A bound _ (payload branch, cycle element, implicit lambda) keeps its meaning
E3084: _ bound where a function was expected
Operator section
(* 2), (+ "!"), (.<. 1)
Space after operator required; RHS binds at RBP 130 (* 2 + 3\(\equiv\)_ => _ * (2 + 3))
E2031: missing space (>3)
Field-accessor section
(.name), (.0), (.a.b)
Parenthesized leading dot projects field/index with a fresh internal parameter (never shadows outer _)
E2064: bare (.)
Headless choice fn
[< 0] "neg" [0] "zero" | "pos"
Scrutinee-less guarded choice lowers to a 1-arg function over _
—
Headless guard fn
['a'...'z'], ![' ', '\n']
Scrutinee-less bracket guard lowers to a T => <> predicate