gleam

为 Gleam 提供专家级指导 —— 在 Erlang BEAM 虚拟机上运行的类型安全函数式语言。帮助开发者利用 Gleam 的友好语法、穷尽模式匹配及完整的 Erlang/OTP 生态来构建并发和容错应用。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "gleam":https://skillpi.com/zh/skills/deepskill-e88293c50efb63cba06d71ad30435e4a0babf2ef7083436662e153fc7c664b75。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

为 Gleam 提供专家级指导 —— 在 Erlang BEAM 虚拟机上运行的类型安全函数式语言。帮助开发者利用 Gleam 的友好语法、穷尽模式匹配及完整的 Erlang/OTP 生态来构建并发和容错应用。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
软件、账号及付费要求
贝什
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: gleam
description: Expert guidance for Gleam, the type-safe functional language that runs on the Erlang BEAM virtual machine. Helps developers build concurrent, fault-tolerant applications with Gleam's friendly syntax, exhaustive pattern matching, and access to the entire Erlang/OTP ecosystem.
license: Apache-2.0
compatibility: No special requirements
metadata:
  author: terminal-skills
  version: 1.0.0
  category: development
  tags:
  - gleam
  - erlang
  - beam
  - functional
  - type-safe

Gleam — Type-Safe Language for the BEAM

Overview

Gleam, the type-safe functional language that runs on the Erlang BEAM virtual machine. Helps developers build concurrent, fault-tolerant applications with Gleam's friendly syntax, exhaustive pattern matching, and access to the entire Erlang/OTP ecosystem.

Instructions

Project Setup

# Install Gleam
brew install gleam    # macOS
# Or: curl -fsSL https://gleam.run/install | sh

# Create a new project
gleam new my_app
cd my_app

# Run
gleam run

# Test
gleam test

# Build for production
gleam build

Type-Safe Web Server with Wisp

// src/my_app/router.gleam — Type-safe HTTP routing
// Gleam catches errors at compile time — no runtime crashes from typos.

import gleam/http.{Get, Post, Delete}
import gleam/http/request.{type Request}
import gleam/http/response.{type Response}
import gleam/json
import gleam/result
import wisp.{type Request as WispRequest, type Response as WispResponse}

pub fn handle_request(req: WispRequest) -> WispResponse {
  case wisp.path_segments(req) {
    // GET /api/tasks
    ["api", "tasks"] -> list_tasks(req)

    // GET /api/tasks/:id
    ["api", "tasks", id] -> get_task(req, id)

    // POST /api/tasks
    ["api", "tasks"] if req.method == Post -> create_task(req)

    // DELETE /api/tasks/:id
    ["api", "tasks", id] if req.method == Delete -> delete_task(req, id)

    // 404 for everything else
    _ -> wisp.not_found()
  }
}

fn list_tasks(req: WispRequest) -> WispResponse {
  // Pattern matching ensures we handle every case
  case task_service.get_all() {
    Ok(tasks) -> {
      let body = json.array(tasks, task_to_json)
      wisp.json_response(json.to_string_builder(body), 200)
    }
    Error(err) -> {
      wisp.log_error("Failed to list tasks: " <> err)
      wisp.internal_server_error()
    }
  }
}

fn create_task(req: WispRequest) -> WispResponse {
  use body <- wisp.require_json(req)

  // Decode and validate — compiler ensures all fields are handled
  case decode_create_request(body) {
    Ok(create_req) -> {
      case task_service.create(create_req.title, create_req.priority) {
        Ok(task) -> wisp.json_response(
          json.to_string_builder(task_to_json(task)),
          201,
        )
        Error(err) -> wisp.unprocessable_entity()
      }
    }
    Error(_) -> wisp.bad_request()
  }
}

Custom Types and Pattern Matching

// src/my_app/task.gleam — Domain types with exhaustive matching
// The compiler guarantees you handle every variant — impossible to forget a case.

import gleam/option.{type Option, Some, None}

/// Task priority — the compiler ensures you handle all variants
pub type Priority {
  Low
  Medium
  High
  Urgent
}

/// Task status with strict state machine semantics
pub type Status {
  Todo
  InProgress
  Review
  Done
  Cancelled
}

pub type Task {
  Task(
    id: String,
    title: String,
    description: Option(String),
    priority: Priority,
    status: Status,
    assignee: Option(String),
  )
}

/// Validate status transitions — not all transitions are allowed.
/// The compiler ensures every combination is handled.
pub fn transition(from: Status, to: Status) -> Result(Status, String) {
  case from, to {
    // Valid transitions
    Todo, InProgress -> Ok(InProgress)
    InProgress, Review -> Ok(Review)
    Review, Done -> Ok(Done)
    Review, InProgress -> Ok(InProgress)    // Send back for changes

    // Any status can be cancelled
    _, Cancelled -> Ok(Cancelled)

    // Can't move backwards to Todo
    _, Todo -> Error("Cannot move back to Todo")

    // Can't skip steps
    Todo, Done -> Error("Must go through InProgress and Review first")
    Todo, Review -> Error("Must go through InProgress first")

    // Already in target state
    same, target if same == target -> Ok(target)

    // Everything else is invalid
    _, _ -> Error("Invalid status transition")
  }
}

/// Calculate SLA based on priority — exhaustive, no default needed
pub fn sla_hours(priority: Priority) -> Int {
  case priority {
    Low -> 72
    Medium -> 24
    High -> 8
    Urgent -> 2
  }
}

Concurrency with OTP Actors

// src/my_app/task_actor.gleam — Concurrent actor for task management
// Gleam runs on the BEAM — millions of lightweight processes, fault-tolerant.

import gleam/erlang/process.{type Subject}
import gleam/otp/actor.{type Next}

/// Messages the actor can receive
pub type Message {
  GetAll(reply_to: Subject(List(Task)))
  Create(title: String, priority: Priority, reply_to: Subject(Result(Task, String)))
  UpdateStatus(id: String, status: Status, reply_to: Subject(Result(Task, String)))
}

/// Actor state
pub type State {
  State(tasks: List(Task), next_id: Int)
}

/// Handle each message type
fn handle_message(message: Message, state: State) -> Next(Message, State) {
  case message {
    GetAll(reply_to) -> {
      process.send(reply_to, state.tasks)
      actor.continue(state)
    }

    Create(title, priority, reply_to) -> {
      let id = "task-" <> int.to_string(state.next_id)
      let task = Task(
        id: id,
        title: title,
        description: None,
        priority: priority,
        status: Todo,
        assignee: None,
      )
      process.send(reply_to, Ok(task))
      actor.continue(State(
        tasks: [task, ..state.tasks],
        next_id: state.next_id + 1,
      ))
    }

    UpdateStatus(id, new_status, reply_to) -> {
      let result = update_task_status(state.tasks, id, new_status)
      case result {
        Ok(updated_tasks) -> {
          process.send(reply_to, Ok(find_task(updated_tasks, id)))
          actor.continue(State(..state, tasks: updated_tasks))
        }
        Error(err) -> {
          process.send(reply_to, Error(err))
          actor.continue(state)
        }
      }
    }
  }
}

/// Start the actor
pub fn start() -> Result(Subject(Message), actor.StartError) {
  actor.start(State(tasks: [], next_id: 1), handle_message)
}

Installation

# macOS
brew install gleam

# Linux
curl -fsSL https://gleam.run/install | sh

# Dependencies
gleam add wisp           # Web framework
gleam add gleam_json     # JSON encoding/decoding
gleam add sqlight        # SQLite bindings
gleam add gleam_http     # HTTP types

Examples

Example 1: Building a feature with Gleam

User request:

Add a real-time collaborative project setup to my React app using Gleam.

The agent installs the package, creates the component with proper Gleam initialization, implements the project setup with event handling and state management, and adds TypeScript types for the integration.

Example 2: Migrating an existing feature to Gleam

User request:

I have a basic type-safe web server with wisp built with custom code. Migrate it to use Gleam for better type-safe web server with wisp support.

The agent reads the existing implementation, maps the custom logic to Gleam's API, rewrites the components using Gleam's primitives, preserves existing behavior, and adds features only possible with Gleam (like Custom Types and Pattern Matching, Concurrency with OTP Actors).

Guidelines

  1. Let the compiler help — Gleam's type system catches bugs at compile time; if it compiles, it almost certainly works
  2. Use custom types over strings — Define Priority and Status as custom types, not strings; the compiler ensures you handle every variant
  3. Pattern matching for control flow — Replace if/else chains with pattern matching; the compiler warns about missing cases
  4. Result type over exceptions — Gleam has no exceptions; use Result(value, error) and use syntax for error handling
  5. Leverage the BEAM — Gleam runs on Erlang's VM; you get fault tolerance, hot code reloading, and millions of concurrent processes for free
  6. Call Erlang/Elixir libraries — Use @external to call any Erlang or Elixir library; the entire OTP ecosystem is available
  7. Pipelines for data transformation — Use |> operator for readable data pipelines: data |> filter |> map |> sort
  8. Actors for state — Use OTP actors (via gleam_otp) for concurrent stateful services; each actor is isolated and crash-safe

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值88/100

亮点

  • 提供 Gleam 语言全栈开发指导,涵盖 Web 服务、类型系统、并发模型
  • 面向开发者解决类型安全与 BEAM 生态集成的实际工程需求
  • 内容深度高,含生产级代码示例和最佳实践
触发精准92/100

亮点

  • 触发词精准覆盖 Gleam 核心特性(类型安全、BEAM、OTP、模式匹配)
  • 边界清晰,不易与其他函数式语言工具混淆
结构规范85/100

待提升项

  • 缺少 When to Use 章节 原报告严重程度:轻微

    文档结构完整但未显式标注适用场景章节

    改进建议:建议在 Overview 后添加 "When to Use" 章节明确使用时机

亮点

  • Phase 划分清晰(Setup → Web Server → Types → Concurrency)
  • 含完整端到端代码示例和迁移案例
  • frontmatter 元数据完整规范
执行可靠94/100

亮点

  • 所有工具链命令来自 Gleam 官方源,参数正确
  • 类型系统确保编译时错误捕获,Result 类型处理运行时异常
  • OTP Actor 模型提供故障隔离和状态安全
证据可验 (前四项均值)90/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 33, 262 行
文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • gleam.run

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

贝什

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。