gleam-erlang-interoplisted
Install: claude install-skill Underwater-AI/uwater_app
# 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.
```gleam
// 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
@ext