Gleam Erlang Interop
БесплатноБез исполняемых скриптовНе проверенUse when gleam-Erlang interoperability including calling Erlang code from Gleam, using Erlang libraries, external functions, working with Erlang types, NIFs…
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
Gleam Erlang Interop
Introduction
Gleam compiles to Erlang, enabling seamless interoperability with the vast Erlang ecosystem. This interop allows Gleam developers to leverage battle-tested Erlang libraries while writing type-safe Gleam code, combining modern language features with decades of production-proven libraries.
The interop mechanism uses external functions to call Erlang code, with Gleam's type system providing safety at the boundary. Gleam can call any Erlang function, use Erlang processes, and integrate with OTP behaviors while maintaining type safety.
This skill covers external function declarations, calling Erlang modules, working with Erlang types, using Erlang standard library, NIFs and ports, and patterns for safe type boundaries when integrating with Erlang code.
External Function Declarations
External functions declare Erlang functions with Gleam types, providing typed interfaces to Erlang code.
// Basic external function
@external(erlang, "erlang", "list_to_binary")
pub fn list_to_binary(list: List(Int)) -> BitArray
// Using external functions
pub fn convert_list() {
let list = [72, 101, 108, 108, 111]
let binary = list_to_binary(list)
io.debug(binary)
}
// External function with multiple arguments
@external(erlang, "string", "concat")
pub fn string_concat(a: String, b: String) -> String
pub fn join_strings() {
let result = string_concat("Hello, ", "World!")
io.debug(result)
}
// External function returning Result
@external(erlang, "file", "read_file")
fn erlang_read_file(path: String) -> Result(BitArray, Dynamic)
pub fn read_file(path: String) -> Result(String, String) {
case erlang_read_file(path) {
Ok(contents) -> {
case bit_array.to_string(contents) {
Ok(str) -> Ok(str)
Error(_) -> Error("Invalid UTF-8")
}
}
Error(_) -> Error("File read error")
}
}
// External function with erlang types
@external(erlang, "maps", "get")
fn map_get(key: a, map: Map(a, b)) -> Result(b, Nil)
@external(erlang, "maps", "put")
fn map_put(key: a, value: b, map: Map(a, b)) -> Map(a, b)
// Using Erlang's timer module
@external(erlang, "timer", "sleep")
pub fn sleep(milliseconds: Int) -> Nil
pub fn wait_a_second() {
io.println("Waiting...")
sleep(1000)
io.println("Done!")
}
// External function with tuples
@external(erlang, "calendar", "local_time")
pub fn local_time() -> #(#(Int, Int, Int), #(Int, Int, Int))
pub fn get_current_time() {
let #(date, time) = local_time()
let #(year, month, day) = date
let #(hour, minute, second) = time
io.debug(#(year, month, day, hour, minute, second))
}
// External functions with atoms
pub type Atom
@external(erlang, "erlang", "binary_to_atom")
fn binary_to_atom(binary: BitArray) -> Atom
@external(erlang, "erlang", "atom_to_binary")
fn atom_to_binary(atom: Atom) -> BitArray
// Creating safe wrappers
pub opaque type ErlangAtom {
ErlangAtom(atom: Dynamic)
}
pub fn atom_from_string(str: String) -> ErlangAtom {
let bits = bit_array.from_string(str)
let atom = binary_to_atom(bits)
ErlangAtom(atom: dynamic.from(atom))
}
// External function with callbacks
@external(erlang, "lists", "map")
pub fn erlang_map(f: fn(a) -> b, list: List(a)) -> List(b)
pub fn double_list(list: List(Int)) -> List(Int) {
erlang_map(fn(x) { x * 2 }, list)
}
// Process-related external functions
@external(erlang, "erlang", "self")
pub fn self() -> process.Pid
@external(erlang, "erlang", "spawn")
pub fn spawn(f: fn() -> Nil) -> process.Pid
// System external functions
@external(erlang, "erlang", "system_time")
fn system_time_nanos() -> Int
pub fn current_timestamp() -> Int {
system_time_nanos() / 1_000_000
}
External declarations bridge Gleam's type system with Erlang's dynamic runtime.
Using Erlang Standard Library
Gleam can leverage Erlang's comprehensive standard library for various operations.
// Crypto module
@external(erlang, "crypto", "hash")
fn crypto_hash(algorithm: Atom, data: BitArray) -> BitArray
pub fn sha256(data: String) -> BitArray {
let algo = atom_from_string("sha256")
let bits = bit_array.from_string(data)
crypto_hash(algo.atom, bits)
}
pub fn md5(data: String) -> String {
let algo = atom_from_string("md5")
let bits = bit_array.from_string(data)
let hash = crypto_hash(algo.atom, bits)
bit_array.base16_encode(hash, False)
}
// Random module
@external(erlang, "rand", "uniform")
fn uniform() -> Float
@external(erlang, "rand", "uniform")
fn uniform_int(n: Int) -> Int
pub fn random_float() -> Float {
uniform()
}
pub fn random_int(max: Int) -> Int {
uniform_int(max)
}
pub fn random_choice(list: List(a)) -> Option(a) {
case list {
[] -> None
items -> {
let index = uniform_int(list.length(items))
list.at(items, index - 1)
}
}
}
// ETS (Erlang Term Storage)
pub type EtsTable
@external(erlang, "ets", "new")
fn ets_new(name: Atom, options: List(Atom)) -> EtsTable
@external(erlang, "ets", "insert")
fn ets_
Установить Gleam Erlang Interop в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Gleam Erlang Interop?
Use when gleam-Erlang interoperability including calling Erlang code from Gleam, using Erlang libraries, external functions, working with Erlang types, NIFs, and leveraging the BEAM ecosystem from Gleam applications.
Как установить скилл Gleam Erlang Interop?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Gleam Erlang Interop запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic