Live demos — built with Axon, running in your browser
🔢 Bounded Counter CounterState
Pure counter_inc / counter_dec functions. Bounds [-10, 10] enforced by type. counter_display() uses string interpolation "+{n}".
✉️ Email Validator EmailAddress
EmailAddress = string where matches(#email). Auto-injected guard at send_welcome() boundary. Live feedback via validate_email().
🔘 Toggle Switch toggle_css_class
CSS class composed with "{ baseClass } { baseClass }--on" — string interpolation makes class composition readable and intent-clear.
Theme Switcher theme_class
"theme-{name}" interpolation generates the body class. theme_label() is a @pure @total @memo match expression.
🪟 Modal Dialog ModalState
modal_open() and modal_close() are pure state transitions — no class manipulation, just immutable record updates.
@memo Cache @memo
fibonacci() and triangle_number() are annotated @pure @total @memo. The transpiler wraps them in a Map-based cache — recursive calls skip recomputation.
📄 View Axon source — v0.3 feature showcase
// Axon v0.3 — Web Controls Demo

// ── Constrained types ────────────────────────────────────────────────
type NonEmptyString = string where length > 0
type EmailAddress   = string where matches(#email)
type Score          = int    where >= 0 && <= 100
type BoundedCount   = int    where >= -10 && <= 10
type ThemeName      = string

// ── String interpolation (v0.3) ───────────────────────────────────────
fn counter_display :: (state: CounterState) -> string {
  @pure @total
  let n = state.count
  match n {
    | > 0 => "+{n}"        // "+" + n.toString() — no concatenation
    | < 0 => "{n}"
    | _   => "0"
  }
}

fn toggle_css_class(state, baseClass) =
  state ? "{baseClass} {baseClass}--on"
        : "{baseClass} {baseClass}--off"

fn theme_class(name) = "theme-{name}"   // body class without concatenation

// ── .field shorthand (v0.3) ───────────────────────────────────────────
fn top_players :: (players: Player[]) -> string[] {
  @pure @total
  players |> filter(.active) |> map(.name)   // no lambdas needed
}

// ── @memo annotation (v0.3) ───────────────────────────────────────────
fn fibonacci :: (n: int) -> int {
  @pure @total @memo
  match n {
    | 0 => 0
    | 1 => 1
    | _ => fibonacci(n-1) + fibonacci(n-2)   // cached after first call
  }
}

// ── Param validation injection (v0.3) ────────────────────────────────
fn send_welcome :: (email: EmailAddress, name: NonEmptyString) -> string {
  @pure @total
  // Guard injected at compile time — __validate_EmailAddress(email) auto-called
  "Welcome, {name}! Confirmation sent to {email}."
}
Loading…