// Precompiled renderers (ADR 0054): a render of a statically known tree // appends static chunks and escapes holes straight into the builder; // the Element tree is never built. Behaviour is unchanged, on both // backends — the holes' side effects keep their order, and a tree that // escapes (matched on, rendered twice) is still built. import std/html.{type Element, type Html, raw, text} import std/io import std/list effect log { fn log :: msg: String -> () } fn with_log :: action: fn() -> a / -> a / { handle { action () } with { log m -> io.println ("log: " <> m) } } fn traced :: mark: String value: String -> String / { log mark value } // A row with a side effect: the map fusion keeps the rows' effects in // order (the renders they interleave with are pure). fn row :: name: String -> Html / { log ("row " <> name) {text name} } fn table :: names: List -> Html / { {list.map names row}
} // A component whose body is a match: each arm renders in place. fn badge :: fresh: Bool -> Html { match fresh { True -> new , False -> used } } // A tree in a wrapper: matched on, it escapes the render pipeline. type Wrapped { Wrapped(Html) } fn unwrap :: w: Wrapped -> Html { match w { Wrapped(t) -> t } } pub fn main :: -> () / { use <- with_log // A direct literal at the render site. io.println (html.render (

static & {traced "hole" "escaped "}

)) // A component call at the render site (a match body). io.println (html.render (badge True)) io.println (html.render (badge False)) // The same component twice in one literal: each call renders its own. io.println (html.render (
{badge True}{badge False}
)) // The rows of a table, fused: the row effects stay in order. io.println (html.render (table ["a", "b"])) // But not across an effect: the map's evaluation may not move past // the log — the list is built first, as today. let rows = list.map ["c", "d"] row log "built" io.println (html.render ({rows}
)) // A tree that escapes is still built: wrapped, matched on, then // rendered (the projection is no longer a construction site). let w = Wrapped(
body
) io.println (html.render (unwrap w)) // Rendered twice: the same output twice. let twice =

again

io.println (html.render twice) io.println (html.render twice) // Every void element, with children (dropped) and no closing tag. io.println ( html.render (
{text "x"}
{text "x"}

) ) // A flag that is off renders nothing; a raw hole is not escaped. io.println (html.render ()) io.println (html.render (

{raw "trusted"}

)) // A lambda as the row: the fold step renders its body directly. io.println (html.render (
    {list.map ["x", "y"] fn n {
  • {text n}
  • }}
)) } //> log: hole //>

static & escaped <here>

//> new //> used //>
newused
//> log: row a //> log: row b //>
a
b
//> log: row c //> log: row d //> log: built //>
c
d
//>
body
//>

again

//>

again

//>


//> //>

trusted

//>
  • x
  • y