Skip to content

Language Design

2 posts with the tag “Language Design”

Template strings in Rust

Template strings have become widespread in modern programming languages, but Rust is a notable exception. Here I want to shed light on the design space and rationale for template strings in Rust, and present a proposal.

Template strings allow interpolating values in a string. Some languages also support custom template strings for specialized use cases:

// template string in JavaScript
`Hello, ${person.name}!`
// tagged template string
sql`SELECT * FROM users WHERE id = ${handle} ORDER BY ${sortField};`
// this is equivalent to...
sql(
["SELECT * FROM users WHERE id = ", " ORDER BY ", ";"],
handle, sortField
)

Effects in Rust (and Koka)

What is an effect system? According to Wikipedia, it is a formal system that describes the computational effects of computer programs, such as side effects. It is also an extension of a type system, and allows you to statically verify that your program is sound with regard to effects.

If you want to fully understand this concept, I recommend you to learn Koka. It is a beautiful language with a powerful, yet easy to understand effect system. This blog post includes Koka snippets, but they should be easy to understand without prior knowledge.