gleam
FreeNo executable scriptsNot checkedGleam is a statically typed functional language that compiles to Erlang (BEAM) or JavaScript. Use when creating Gleam projects, writing custom types and…
by TerminalSkills★ 221 GitHub starsAbout this skill
Gleam — Type-Safe Language for the BEAM
Overview
Gleam is a small, statically typed functional language. It compiles to Erlang and runs on the BEAM virtual machine (fault-tolerant, many lightweight processes), or compiles to JavaScript. There are no exceptions, no null, and no implicit conversions: errors are Result values and case expressions must be exhaustive. Current release: 1.19.2 (the language is 1.x, and the standard library gleam_stdlib is 1.x too). Web code in this skill targets Erlang, because Wisp, Mist and OTP actors are Erlang-only.
Instructions
Project setup
Install Gleam with a package manager (brew install gleam on macOS and Linuxbrew; your distribution's package or mise/asdf also work), or download the release archive from https://github.com/gleam-lang/gleam/releases and check it against the .sha256 file published next to it. The Erlang target also needs Erlang/OTP installed (the compiler calls escript); the JavaScript target needs a JS runtime instead.
gleam new task_api # Erlang target by default; add --template javascript for JS
cd task_api
gleam add wisp mist gleam_json gleam_otp gleam_erlang gleam_http
gleam run # build and run src/task_api.gleam main()
gleam test # runs gleeunit tests in test/
gleam check # type check only
gleam format # format source
gleam run --target javascript # run on Node instead (pure code only)
gleam add writes version ranges into gleam.toml; gleam deps update refreshes them. Packages live on Hex (https://hex.pm). Note that gleam_otp 1.x has a new actor API and wisp 2.x changed several helpers; many older blog posts show removed functions.
Custom types and pattern matching
// src/task_api/task.gleam
import gleam/option.{type Option, None, Some}
pub type Priority {
Low
Medium
High
Urgent
}
pub type Status {
Todo
InProgress
Review
Done
Cancelled
}
pub type Task {
Task(id: String, title: String, priority: Priority, status: Status, assignee: Option(String))
}
/// Only some status changes are allowed; the compiler checks every pair is covered.
pub fn transition(from: Status, to: Status) -> Result(Status, String) {
case from, to {
Todo, InProgress -> Ok(InProgress)
InProgress, Review -> Ok(Review)
Review, Done -> Ok(Done)
Review, InProgress -> Ok(InProgress)
Done, _ | Cancelled, _ -> Error("Finished tasks cannot change status")
_, Cancelled -> Ok(Cancelled)
_, _ -> Error("Invalid status transition")
}
}
/// No default branch needed: adding a Priority variant breaks the build until handled.
pub fn sla_hours(priority: Priority) -> Int {
case priority {
Low -> 72
Medium -> 24
High -> 8
Urgent -> 2
}
}
pub fn describe(task: Task) -> String {
case task.assignee {
Some(name) -> task.title <> " (" <> name <> ")"
None -> task.title <> " (unassigned)"
}
}
JSON encoding and decoding
gleam_json 3.x encodes with json.object/json.string and decodes with the gleam/dynamic/decode module (the old dynamic.field decoders are gone).
import gleam/dynamic/decode
import gleam/json
pub type NewTask {
NewTask(title: String, priority: String)
}
fn new_task_decoder() -> decode.Decoder(NewTask) {
use title <- decode.field("title", decode.string)
use priority <- decode.field("priority", decode.string)
decode.success(NewTask(title:, priority:))
}
pub fn parse(input: String) -> Result(NewTask, json.DecodeError) {
json.parse(input, new_task_decoder())
}
pub fn encode(task: NewTask) -> String {
json.object([
#("title", json.string(task.title)),
#("priority", json.string(task.priority)),
])
|> json.to_string
}
Web server with Wisp and Mist, state in an OTP actor
Wisp (2.x) is the web framework; Mist is the HTTP server it runs on. Handlers take a wisp.Request and return a wisp.Response; route with gleam/http/request.path_segments and the request method. Bodies are strings (wisp.json_response(json_string, status)).
// src/task_api.gleam
import gleam/dynamic/decode
import gleam/erlang/process
import gleam/http.{Get, Post}
import gleam/http/request
import gleam/int
import gleam/json
import gleam/list
import gleam/otp/actor
import mist
import wisp.{type Request, type Response}
import wisp/wisp_mist
pub type Task {
Task(id: String, title: String)
}
pub type Message {
GetAll(reply_to: process.Subject(List(Task)))
Create(title: String, reply_to: process.Subject(Task))
}
pub type State {
State(tasks: List(Task), next_id: Int)
}
fn handle_message(state: State, message: Message) -> actor.Next(State, Message) {
case message {
GetAll(reply_to) -> {
process.send(reply_to, list.reverse(state.tasks))
actor.continue(state)
}
Create(title, reply_to) -> {
let task = Task("task-" <> int.to_string(state.next_id), title)
process.send(reply_to, task)
Install gleam in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the gleam skill do?
Gleam is a statically typed functional language that compiles to Erlang (BEAM) or JavaScript. Use when creating Gleam projects, writing custom types and pattern matching, building web servers with Wisp and Mist, running OTP actors, or adding dependencies with gleam add. Covers Gleam 1.x and current package APIs.
How do I install the gleam skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the gleam skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
by Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
by Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
by Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
by Anthropic