Companion film
Name the logic. Close the state.
Change one order total and watch a named pricing function and a closed Order choice update the decision while the ledger stays intact.
49 secGrid 0.63.2
Open film page →Canonical Grid model
In-model named functions: inferred signatures, polymorphic reuse, open records, and lambda composition.
What this model gives you
15 min to study · Source reviewed 2026-08-25
Continue with guided practiceExpected checkpoint
After loading the canonical fee rate and three-job ledger.
Fee, premium, floor, shape, and total logic are authored once and reused.
Identity works for numbers and text, while open records accept useful extra fields.
MAP and REDUCE reuse the same definitions over the complete job ledger.
MODEL "Named Function Toolkit"
DESCRIPTION "In-model named functions: inferred signatures, polymorphic reuse, open records, and lambda composition."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "canonical", "functions", "inference", "composition"
# Named definitions: Grid infers one generalized type scheme per name
identity(value) = value
net_of_fee(amount, fee_rate) = amount * (1 - fee_rate)
rush_premium(job) = job.amount * job.rush_rate
floor_at(value, minimum) = MAX(value, minimum)
same_shape(values) = MAP(values, value => value)
billed_total(jobs) = REDUCE(0, jobs, (acc, job) => acc + job.amount)
# Inputs
A1 IS percentage = 12pct
A2 IS currency = 400
# Job ledger: open record rows, so extra fields stay welcome
Jobs = [
{ client: "Meridian", amount: 5200, rush_rate: 0.25 },
{ client: "Bluefin", amount: 3100, rush_rate: 0 },
{ client: "Harbor", amount: 7400, rush_rate: 0.1 }
]
# Polymorphic reuse: each call instantiates a fresh scheme
B1 = identity(42)
B2 = identity("invoice-run")
# Direct calls against scalars and object literals
C1 IS currency = net_of_fee(5200, A1)
C2 IS currency = rush_premium({ amount: 7400, rush_rate: 0.1, note: "expedited" })
C3 IS currency = floor_at(C1 - 6000, 0)
# Composing named functions with lambdas
D1 = MAP(Jobs, job => net_of_fee(job.amount, A1))
D2 = MAP(Jobs, job => rush_premium(job))
D3 IS currency = billed_total(Jobs)
D4 IS currency = REDUCE(0, D2, (acc, value) => acc + value)
D5 = MAP(D1, value => floor_at(value - A2, 0))
# Collection protocols: same_shape accepts any Mappable constructor
H1 = same_shape([10, 20, 30])
H2 = same_shape(Jobs)
# Summary
L1 IS currency = D3 * (1 - A1) + D4
L2 = L1 > 12000 THEN "healthy-month" ELSE "lean-month"
L3 = TEXT(L1, "0.00")
L4 = `net={L3} status={L2}`
END MODEL