Nickel language preview
1. Contracts and records
let bindings, annotations, and merging
horizon-dark
let Port = std.contract.from_predicate (fun p =>
std.is_number p && p > 0 && p < 65536) in
{
host | String = "localhost",
port | Port = 8080,
url = "http://%{host}:%{std.to_string port}",
} atom-one-dark
let Port = std.contract.from_predicate (fun p =>
std.is_number p && p > 0 && p < 65536) in
{
host | String = "localhost",
port | Port = 8080,
url = "http://%{host}:%{std.to_string port}",
} github-dark
let Port = std.contract.from_predicate (fun p =>
std.is_number p && p > 0 && p < 65536) in
{
host | String = "localhost",
port | Port = 8080,
url = "http://%{host}:%{std.to_string port}",
} dracula
let Port = std.contract.from_predicate (fun p =>
std.is_number p && p > 0 && p < 65536) in
{
host | String = "localhost",
port | Port = 8080,
url = "http://%{host}:%{std.to_string port}",
} nord
let Port = std.contract.from_predicate (fun p =>
std.is_number p && p > 0 && p < 65536) in
{
host | String = "localhost",
port | Port = 8080,
url = "http://%{host}:%{std.to_string port}",
} github
let Port = std.contract.from_predicate (fun p =>
std.is_number p && p > 0 && p < 65536) in
{
host | String = "localhost",
port | Port = 8080,
url = "http://%{host}:%{std.to_string port}",
} 2. Functions and enums
fun expressions and enum tags
horizon-dark
let classify = fun n =>
if n > 0 then 'Positive
else if n < 0 then 'Negative
else 'Zero in
{
result = classify 42,
values = std.array.map (fun x => x * 2) [1, 2, 3],
} atom-one-dark
let classify = fun n =>
if n > 0 then 'Positive
else if n < 0 then 'Negative
else 'Zero in
{
result = classify 42,
values = std.array.map (fun x => x * 2) [1, 2, 3],
} github-dark
let classify = fun n =>
if n > 0 then 'Positive
else if n < 0 then 'Negative
else 'Zero in
{
result = classify 42,
values = std.array.map (fun x => x * 2) [1, 2, 3],
} dracula
let classify = fun n =>
if n > 0 then 'Positive
else if n < 0 then 'Negative
else 'Zero in
{
result = classify 42,
values = std.array.map (fun x => x * 2) [1, 2, 3],
} nord
let classify = fun n =>
if n > 0 then 'Positive
else if n < 0 then 'Negative
else 'Zero in
{
result = classify 42,
values = std.array.map (fun x => x * 2) [1, 2, 3],
} github
let classify = fun n =>
if n > 0 then 'Positive
else if n < 0 then 'Negative
else 'Zero in
{
result = classify 42,
values = std.array.map (fun x => x * 2) [1, 2, 3],
} 3. Interpolation with a nested record
a %{...} interpolation containing a bare {..} record literal
horizon-dark
let user = { name = "Bob", age = 30 } in
{ greeting = "Hello, %{ {name = user.name}.name }!" } atom-one-dark
let user = { name = "Bob", age = 30 } in
{ greeting = "Hello, %{ {name = user.name}.name }!" } github-dark
let user = { name = "Bob", age = 30 } in
{ greeting = "Hello, %{ {name = user.name}.name }!" } dracula
let user = { name = "Bob", age = 30 } in
{ greeting = "Hello, %{ {name = user.name}.name }!" } nord
let user = { name = "Bob", age = 30 } in
{ greeting = "Hello, %{ {name = user.name}.name }!" } github
let user = { name = "Bob", age = 30 } in
{ greeting = "Hello, %{ {name = user.name}.name }!" } 4. Multiline strings
m%"..."% strings with a matching %-count delimiter
horizon-dark
let template = m%"
Use %{host} with a literal "%" sign here.
"%
in
{ rendered = template } atom-one-dark
let template = m%"
Use %{host} with a literal "%" sign here.
"%
in
{ rendered = template } github-dark
let template = m%"
Use %{host} with a literal "%" sign here.
"%
in
{ rendered = template } dracula
let template = m%"
Use %{host} with a literal "%" sign here.
"%
in
{ rendered = template } nord
let template = m%"
Use %{host} with a literal "%" sign here.
"%
in
{ rendered = template } github
let template = m%"
Use %{host} with a literal "%" sign here.
"%
in
{ rendered = template }