Exploring Functional Programming with Gleam
Documenting the first steps with learning Gleam
- 2 min read
Getting Started with Gleam
Gleam is a functional programming language that runs on the Erlang virtual machine (BEAM). It has a strong type system, which helps catch mistakes before your program runs. It’s also designed to work well with Erlang and Elixir, making it great for building reliable and scalable applications.
Who Created Gleam?
Gleam was created by Louis Pilfold. He wanted a language that combined the reliability of the Erlang ecosystem with a more structured and easy-to-use type system. Gleam takes inspiration from languages like OCaml and Elm, focusing on simplicity and performance.
Installing Gleam
To start using Gleam, you first need to install it. Here’s how to do that on macOS and Linux.
macOS (Homebrew)
brew install gleam
Linux (via script)
curl -fsSL https://gleam.run/install.sh | sh
Once installed, you can check if it worked by running:
gleam --version
Creating a New Gleam Project
Now that Gleam is installed, you can create a new project by running:
gleam new hello_gleam
This command sets up a new Gleam project with everything you need to get started. Change into your project’s directory:
cd hello_gleam
Writing a Hello World Program
Let’s write a simple program that prints “Hello, world!” to the screen.
Open the src/hello_gleam.gleam
file and add this code:
import gleam/io
pub fn main() {
io.println("Hello, world!")
}
To compile and run the program, use:
gleam run
You should see:
Hello, world!
Wrapping Up
Gleam is a great choice for anyone interested in functional programming and reliable software. With its strong type system and the power of the Erlang VM, it’s an exciting language to explore. If you’re looking for something new and fun to learn, give Gleam a try!