Gleam is a type safe and scalable language for the Erlang virtual machine and JavaScript runtimes. Today Gleam v0.17.0 has been released! Let’s take a look at some of the new changes.

Better code generation

The JavaScript code generated by the compiler has been redesigned making it easier to debug, easier to use from JavaScript, and to reduce generated code size.

The previous design would use JavaScript arrays and objects to create Gleam’s immutable data structures. This could be confusing when printed or when the code is read, and it was unclear how to create these data structures from JavaScript. Now the constructors can be imported and used like normal JavaScript code.

import { List, Ok, Error, inspect } from "gleam_package/gleam.js";

// Construct a list of results
let list = List.fromArray([
  new Ok(1),
  new Ok(2),
  new Error("Oh no!"),
]);

// Print the list in Gleam syntax
console.log(inspect(list));

It is intended for Gleam code to be easy to use from other languages, so the developer experience of Gleam when writing Gleam or when writing other languages is something we want to always be improving.

Cross platform libraries

With the previous v0.16 release Gleam gained a new backend for the compiler that targets JavaScript, enabling Gleam to run anywhere JavaScript can run. With this release Gleam’s standard library and HTTP library have been updated to work both with Erlang or with JavaScript.

Erlang specific code in the standard library (such as the module for working with Erlang atoms) has been extracted out into the Gleam Erlang library.

For JavaScript a Gleam JavaScript library has been created with type safe bindings for arrays, mutable references, promises, and more.

JavaScript build script

When compiling to Erlang Gleam projects typically piggyback off of Erlang or Elixir by using their build tools rebar3 and mix. To give JavaScript based Gleam projects a way to get going a JavaScript build script has been created that can compile a project and its dependencies.

To see it in action along with the libraries above check out this micro Gleam serverless app deployed to CloudFlare Workers. See the app running here.

In future we will release the upcoming Gleam build tool which will replace this script along with mix and rebar3 for Gleam projects. ✨

Conditional compilation

To enable cross-platform libraries that work on both Erlang and JavaScript Gleam v0.17.0 introduces a limited form of conditional compilation. With this feature statements can be included or excluded from compilation based upon the compiler target.

In this code the current_target constant is defined to an appropriate value depending on the target.

if erlang {
  pub const current_target = "Erlang"
}

if javascript {
  pub const current_target = "JavaScript"
}

In addition to these this release also includes support for basic bit string literals when compiling to JavaScript, support for patterns with the try keyword, and a ton of bug fixes. For all the details check out the changelog.

How can I try it?

Instructions on how to install the latest version of Gleam can be found on the getting started page of the website.

Once installed you can follow the guide for information on getting started compiling to Erlang, or this Gleam JavaScript template can be used for writing and running Gleam code on JavaScript.

The CloudFlare Workers template can be used if you’d like to try their serverless platform with Gleam.

Supporting Gleam

If you would like to support me in making Gleam please consider sponsoring Gleam or asking your employer to sponsor Gleam. Every donation makes a difference, no matter how small, so thank you for your help.

⭐ Or alternatively give us a star on GitHub! ⭐

Thank you

Gleam is made possible by the support of all the people who have sponsored and contributed to the project. Thank you all!

Thanks for reading! Have fun! 💜