# Gleam — Friendly Type-Safe Language for the BEAM > Gleam is a statically typed functional language that compiles to Erlang and JavaScript, combining type safety with the fault-tolerant BEAM runtime. ## Install Save as a script file and run: # Gleam — Friendly Type-Safe Language for the BEAM ## Quick Use ```bash # Install via Homebrew or shell script brew install gleam # Create a new project gleam new my_app && cd my_app gleam run ``` ## Introduction Gleam is a statically typed functional programming language designed for building reliable systems on the Erlang BEAM virtual machine. It also compiles to JavaScript, letting you share code between server and browser. Gleam offers a friendly developer experience with helpful error messages and a consistent, small language surface. ## What Gleam Does - Compiles to both Erlang and JavaScript from a single codebase - Provides full static type checking with type inference - Interoperates seamlessly with Erlang, Elixir, and OTP libraries - Ships with a built-in package manager, build tool, formatter, and LSP - Produces fault-tolerant applications using BEAM supervision trees ## Architecture Overview Gleam's compiler is written in Rust and parses `.gleam` source files into a typed AST. It then emits either Erlang source or JavaScript modules. On the BEAM side, the generated Erlang is compiled to bytecode and runs inside the standard OTP runtime, gaining access to lightweight processes, supervisors, and distributed messaging out of the box. ## Self-Hosting & Configuration - Install via Homebrew (`brew install gleam`), Nix, or prebuilt binaries from GitHub releases - Requires Erlang/OTP 26+ for BEAM targets; Node.js 18+ for JavaScript targets - Project config lives in `gleam.toml` (dependencies, target, name) - Dependencies are fetched from the Hex package registry - Use `gleam export erlang-shipment` to produce a self-contained release ## Key Features - Exhaustive pattern matching with compile-time guarantees - Use blocks for readable sequential transformations - First-class support for OTP behaviours like GenServer and Supervisor - Sub-second incremental compilation via the Rust-based compiler - Growing ecosystem with packages for HTTP, JSON, databases, and testing ## Comparison with Similar Tools - **Elixir** — dynamic typing with optional Dialyzer specs; Gleam enforces types at compile time - **Erlang** — Gleam adds type safety while compiling to the same BEAM bytecode - **Rust** — targets native binaries with ownership model; Gleam targets BEAM/JS with GC - **OCaml** — similar ML-family type system but lacks BEAM concurrency primitives - **PureScript** — compiles to JS with strong types; Gleam also targets the BEAM ## FAQ **Q: Can I use existing Erlang and Elixir libraries from Gleam?** A: Yes. Gleam has a Foreign Function Interface for calling Erlang and Elixir code directly, and many Hex packages work out of the box. **Q: Is Gleam ready for production?** A: Gleam reached 1.0 in March 2024 and is used in production by several companies. The language and standard library follow semantic versioning. **Q: How does Gleam handle concurrency?** A: On the BEAM target, Gleam uses lightweight Erlang processes and OTP supervisors. On JavaScript, it uses promises and async runtimes. **Q: What editor support is available?** A: Gleam ships an official Language Server Protocol (LSP) implementation providing autocompletion, go-to-definition, and inline error reporting in VS Code, Neovim, Helix, and other editors. ## Sources - https://github.com/gleam-lang/gleam - https://gleam.run --- Source: https://tokrepo.com/en/workflows/d0c47a7a-3ba7-11f1-9bc6-00163e2b0d79 Author: Script Depot