If you use purs-backend-es you'll get optimized code for free. This is a simple example of how it works.
For the code in this file, you need those imports:
module DemoPerf where
import Fmt (fmt)
A simple replacement of strings known at compile time...
greeting1 :: String
greeting1 =
fmt
@"Hello, my name is {name}. I live in {city}."
{ name: "John"
, city: "London"
}
...will compile to a plain JS string:
const greeting1 = "Hello, my name is John. I live in London.";
Replacing strings with values not known at compile time...
greeting2 :: { name :: String, city :: String } -> String
greeting2 =
fmt
@"Hello, my name is {name}. I live in {city}."
...will compile to simple string concatenation:
const greeting2 = (fields) =>
"Hello, my name is " + fields.name + ". I live in " + fields.city + ".";