渲染zh-Hant

scalaria

Translation status: 繁體中文 reader-locale proof. Term names and code fences follow the zh-Hant pack; supporting prose may still be English.

Scalar operations on 整數, 小數, and 布林 in function signatures.

Syntax: 函式 <name>(<scalar-params>) → <scalar-type> <block>

Category#

type

Examples#

radix/corpus/scalaria/scalaria.fab (canonical · concept)#

Scalar operations on 整數, 小數, and 布林 in function signatures.

# =============================================================================
# scalaria — Scalar operations on 整數, 小數, and 布林 in function
# signatures.
# =============================================================================
#
# What this teaches:
#   • Primitive type operations — demonstrates `整數` arithmetic, `小數`
#     division, `布林` comparison and boolean logic in function signatures
#   • Function composition — shows how scalar types compose through parameters
#     and return types
#
# Common mistakes:
#   • Mixing `整數` and `小數` without explicit `↦` 變換 — primitive families have distinct type widths (SEM008).
#
# See also: 整數, 小數, 布林
# =============================================================================



# scalaria — scalar operations on primitive types
#
# Demonstrates 整數, 小數, and 布林 parameters with arithmetic,
# comparison, and boolean logic in function signatures.
#
# GRAMMAR:
#   funcDecl :← '函式' ident '(' paramList ')' ('→' type)? block
#
# EXPECTED OUTPUT:
#   Compile-only declaration tour (no 入口).

fn numerica(int a, int b) → int {
    return (a + b) * 2
}

fn fracta(float a, float b) → float {
    return (a + b) / 2.0
}

fn comparata(int a, int b) → bool {
    return a ≤ b
}

fn logica(bool a, bool b) → bool {
    return not a and b
}