louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
ADR 0034: String interpolation through Show
Status: Proposed (2026-10-13, issue #152); needs engineering review (#44).
Context
Building a string from values is verbose:
show(x)and<>everywhere, as in"listening on " <> show(net.port(server)). There were about 167show(..) <>sites across the examples, std and tests.The question asked: could a type that derives
Showbe used where aStringis expected? That is an implicitShow ⇒ Stringconversion, a subtyping edge in Hindley–Milner. When inference unifiesStringwith an unknownα, it can't tell whetherαis aStringor a value to convert:- types stop being principal;
- results depend on annotations and checking order;
Show<α>constraints leak into inferred signatures.
Rust, Haskell, Gleam, Elm and Koka all avoid it. Louise already keeps its one coercion,
Never, out of unification (ADR 0007).
Decision
No implicit conversion. Every string literal interpolates instead:
fn report :: server: Server request: Request elapsed: Int -> () / <io, log> {
io.println "listening on {net.port server}"
log "got {request.method} {request.path} in {elapsed}ms"
}
fn check :: expected: List<Int> actual: List<Int> -> () {
assert (expected == actual) "expected {expected:?}, got {actual:?}"
}
{e}isshow(e);{e:?}isdebug(e). The trait methods are the prelude'sShowandDebug, whatever the namesshowanddebugmean where the string is (they may be shadowed).Showis the user-facing text, andshowon aStringreturns it unchanged, so"hello {name}"inserts the name as is.Debugquotes strings and names record fields.- A hole holds any expression, including calls, operators, field paths and string literals of its own:
"{list.length(xs)} items","{if ok { "yes" } else { "no" }}". - Typing: each hole adds a
Show<τ>(orDebug<τ>) constraint on its expression's type, exactly as the callshow(e)would. Inference is unaffected: the literal's type isString. - Evaluation: holes are evaluated left to right, and the parts are joined in one allocation (the runtime's
tl_string_join, asstring.concat), not by a chain of<>. - Escapes:
\{and\}are literal braces. An unescaped}outside a hole is an error, so a stray brace is caught rather than kept. 4 existing literals had braces and were escaped. - HTML literals (ADR 0009): a text hole, as in
<td>{user.age}</td>, now takes any type withShowas well asStringandHtml. The value is shown, then escaped like any text.Htmlvalues are still inserted unescaped, and attributes keep their rules (E0601).
Why {e}:
- HTML literals already write holes this way;
- braces were rare in string literals.
The cost falls on text that contains braces, JSON or CSS kept in strings, which must write \{. #108 (CSS) is expected to use its own literal or builder rather than plain strings.
Tooling:
- the formatter leaves string text untouched and formats a hole's expression as code;
- the tree-sitter grammar parses holes as expressions, so editors highlight them as code;
- the language server gives hover and go-to-definition inside holes.
Consequences
- Shorter code for messages, logs and tests, and one allocation instead of one per
<>. - A literal brace needs a backslash. A stray
{in an old string becomes a hole, usually a type error, so the change is loud. - No new trait.
Showis the display trait andDebugthe developer view, as before.
Alternatives considered
- An implicit
Show ⇒ Stringconversion, rejected above. ${e}(JS, Kotlin) or\(e)(Swift): no clash with JSON or CSS text, but unlike HTML literals, and noisier for the common case.- A prefixed literal (
$"…{e}…"): plain strings would never change meaning, but it's one more literal form to learn. The owner chose interpolation in every string. - Holes limited to names and field paths: simpler to scan, but forces a
letfor every call. Any expression it is, as in Rust 2021's inline arguments plus Swift's and Kotlin's expressions. - Only the HTML change (the issue's lighter alternative): done too, but alone it doesn't help logs, errors and plain-text responses.