Skip to main content Svelte Highlight v7.21.1

Gleam language preview

1. Main with imports

import, pub fn, and types
horizon-dark
import gleam/io
import gleam/int

pub fn main() -> Nil {
  let total = add(2, 3)
  io.println("Sum: " <> int.to_string(total))
}

fn add(a: Int, b: Int) -> Int {
  a + b
}
atom-one-dark
import gleam/io
import gleam/int

pub fn main() -> Nil {
  let total = add(2, 3)
  io.println("Sum: " <> int.to_string(total))
}

fn add(a: Int, b: Int) -> Int {
  a + b
}
github-dark
import gleam/io
import gleam/int

pub fn main() -> Nil {
  let total = add(2, 3)
  io.println("Sum: " <> int.to_string(total))
}

fn add(a: Int, b: Int) -> Int {
  a + b
}
dracula
import gleam/io
import gleam/int

pub fn main() -> Nil {
  let total = add(2, 3)
  io.println("Sum: " <> int.to_string(total))
}

fn add(a: Int, b: Int) -> Int {
  a + b
}
nord
import gleam/io
import gleam/int

pub fn main() -> Nil {
  let total = add(2, 3)
  io.println("Sum: " <> int.to_string(total))
}

fn add(a: Int, b: Int) -> Int {
  a + b
}
github
import gleam/io
import gleam/int

pub fn main() -> Nil {
  let total = add(2, 3)
  io.println("Sum: " <> int.to_string(total))
}

fn add(a: Int, b: Int) -> Int {
  a + b
}

2. Custom types and case

type definitions, constructors, and pattern matching
horizon-dark
pub type Shape {
  Circle(radius: Float)
  Square(side: Float)
}

pub fn area(shape: Shape) -> Float {
  case shape {
    Circle(r) -> 3.14 *. r *. r
    Square(s) -> s *. s
  }
}
atom-one-dark
pub type Shape {
  Circle(radius: Float)
  Square(side: Float)
}

pub fn area(shape: Shape) -> Float {
  case shape {
    Circle(r) -> 3.14 *. r *. r
    Square(s) -> s *. s
  }
}
github-dark
pub type Shape {
  Circle(radius: Float)
  Square(side: Float)
}

pub fn area(shape: Shape) -> Float {
  case shape {
    Circle(r) -> 3.14 *. r *. r
    Square(s) -> s *. s
  }
}
dracula
pub type Shape {
  Circle(radius: Float)
  Square(side: Float)
}

pub fn area(shape: Shape) -> Float {
  case shape {
    Circle(r) -> 3.14 *. r *. r
    Square(s) -> s *. s
  }
}
nord
pub type Shape {
  Circle(radius: Float)
  Square(side: Float)
}

pub fn area(shape: Shape) -> Float {
  case shape {
    Circle(r) -> 3.14 *. r *. r
    Square(s) -> s *. s
  }
}
github
pub type Shape {
  Circle(radius: Float)
  Square(side: Float)
}

pub fn area(shape: Shape) -> Float {
  case shape {
    Circle(r) -> 3.14 *. r *. r
    Square(s) -> s *. s
  }
}

3. Literals and externals

True/False/Nil, number bases, and @external
horizon-dark
const enabled = True
const mask = 0xFF
const flags = 0b1010

@external(erlang, "rand", "uniform")
pub fn random() -> Float
atom-one-dark
const enabled = True
const mask = 0xFF
const flags = 0b1010

@external(erlang, "rand", "uniform")
pub fn random() -> Float
github-dark
const enabled = True
const mask = 0xFF
const flags = 0b1010

@external(erlang, "rand", "uniform")
pub fn random() -> Float
dracula
const enabled = True
const mask = 0xFF
const flags = 0b1010

@external(erlang, "rand", "uniform")
pub fn random() -> Float
nord
const enabled = True
const mask = 0xFF
const flags = 0b1010

@external(erlang, "rand", "uniform")
pub fn random() -> Float
github
const enabled = True
const mask = 0xFF
const flags = 0b1010

@external(erlang, "rand", "uniform")
pub fn random() -> Float

4. Pipe operator

|> threading a value through function calls
horizon-dark
import gleam/int
import gleam/string

pub fn describe(n: Int) -> String {
  n
  |> int.to_string
  |> string.append("value: ", _)
}
atom-one-dark
import gleam/int
import gleam/string

pub fn describe(n: Int) -> String {
  n
  |> int.to_string
  |> string.append("value: ", _)
}
github-dark
import gleam/int
import gleam/string

pub fn describe(n: Int) -> String {
  n
  |> int.to_string
  |> string.append("value: ", _)
}
dracula
import gleam/int
import gleam/string

pub fn describe(n: Int) -> String {
  n
  |> int.to_string
  |> string.append("value: ", _)
}
nord
import gleam/int
import gleam/string

pub fn describe(n: Int) -> String {
  n
  |> int.to_string
  |> string.append("value: ", _)
}
github
import gleam/int
import gleam/string

pub fn describe(n: Int) -> String {
  n
  |> int.to_string
  |> string.append("value: ", _)
}