Why is it called Gleam?
Gleam rhymes with and is a synonym of “beam”, which is the name of the Erlang virtual machine.
It’s also a short and cute word that’s hopefully easy to spell and pronounce for most people.
What does Gleam compile to?
Gleam compiles to Erlang or JavaScript.
Will Gleam have type classes?
Type classes are fun and enable creation of very nice, concise APIs, but they can make it easy to make challenging to understand code, tend to have confusing error messages, make consuming the code from other languages much harder, have a high compile time cost, and have a runtime cost unless the compiler performs full-program compilation and expensive monomorphisation. This is unfortunately not a good fit for Gleam and they are not planned.
Will Gleam have metaprogramming?
We are open interested in some form of metaprogramming in Gleam so long as it is not detrimental to Gleam’s readability and fast compilation. If you wish to propose a design for metaprogramming then the process is outlined in this article: How to add metaprogramming to Gleam.
What features are not planned for Gleam?
Gleam will always be a small and cohesive language with a minimal feature set, so there are many features popular in other languages which will not be added to Gleam. This includes, but is not limited to:
- Exception based error handling
- Extensible variants
- Function and operator overloading
- Implicit arguments
- Implicitly nullable values
- Linear or affine types
- Lisp style macros
- Manual memory management
- Mutation
- Object orientation
- Optional arguments
- Type classes or traits
- Untagged unions
Does Gleam have mutable state?
All data structures in Gleam are immutable and are implemented using structural sharing, making them very efficient to update. Typically these are used with functional immutable algorithms to get excellent performance without mutation.
Sometimes mutation is still useful for storing data, caching etc. In these instances databases might be used, or language specific mutable storage such as Erlang's ETS system.
Does Gleam have side effects?
Yes, Gleam is an impure functional language like OCaml or Erlang. Impure actions like writing to files and printing to the console are possible without special handling.
The compiler performs a limited amount of effects tracking internally. This could be extended in future if we have some problem that would benefit from that.
How is message passing typed?
Type safe message passing is implemented in Gleam in libraries, rather than being part of the core language itself. This enables us to run on and interop with both Erlang and JavaScript, two environments that have incompatible concurrency systems.
If you’d like to see more consider checking out the
gleam_erlang and
gleam_otp packages.
Can Gleam use Erlang’s hot code reloading?
All the usual Erlang code reloading features work, but it is not possible to type check the upgrades themselves as we have no way knowing the types of the already running code. This means you would have the usual Erlang amount of safety rather than what you might have with Gleam otherwise.
Generally the OTP libraries for Gleam are optimised for type safety rather than upgrades, and use records rather than atom modules so the state upgrade callbacks may be more complex to write.
Why does division by zero return zero?
There are three common approaches to handling division by zero in programming languages:
- Throw an exception and crash the program.
- Return a special infinity value.
- Return 0.
Gleam does not implicitly throw exceptions, so throwing an exception is not an option. The BEAM VM does not have an infinity value, so that is not an option. Therefore the only option open to Gleam is to return 0 when dividing by zero.
The standard library provides functions which return a result type for division by zero which you can use if that is more suitable for your program.
For more information on division by zero from a mathematical perspective, see this article by Hillel Wayne: 1/0 = 0.
How does Gleam compare to Rust?
Despite having some syntactic similarities, Gleam and Rust are extremely different languages.
-
Rust is a low-level imperative language with controlled mutation, statically verified manual memory management, multiple metaprogramming systems, and a large language surface area. It compiles to native code and has little-to-no runtime.
-
Gleam is a high-level immutable functional language with automatic garbage collection, no metaprogramming, and a small and easy to learn language surface area. It runs on Erlang and JavaScript virtual machines.
Both languages have strong static type systems, and Gleam's developer tooling were inspired in-part by Rust's.
Elixir also has a type system now. What does that mean for Gleam?
Elixir is another language that runs on the Erlang virtual machine, and we're very happy to see Gleam's big-sister language getting types as well.
Elixir and Gleam's type systems are as different as two type systems can be, offering different programming experiences and being designed with different goals in mind. Given they are so different most folks will prefer one to the other, so try them both out and stick with whichever works best for you; You will get the excellence of the BEAM either way!
Can I use Elixir code with Gleam?
Yes! The Gleam build tool has support for Elixir and can compile both Elixir dependencies and Elixir source files in your Gleam project. Elixir has to be installed on your computer for this to work.
Elixir macros cannot be called from outside of Elixir, so some Elixir APIs cannot be used directly from Gleam. To use one of these you can write an Elixir module that uses the macros, and then use that module in your Gleam code.
Why is the compiler written in Rust?
Prototype versions of the Gleam compiler were written in Erlang, but a switch was made to Rust as the lack of static types was making refactoring a slow and error prone process. A full Rust rewrite of the prototype resulted in the removal of a lot of tech debt and bugs, and the performance boost is nice too!
Will the compiler be rewritten in Gleam?
Rewriting the Gleam compiler would take a lot of time, putting all other work on pause for months or years. This is not a good use of our time, and the Gleam version would probably be slower than the current Rust version, so this would not be beneficial for the Gleam community.
Should I put Gleam in production?
Yes!
Gleam is a production-ready programming language and the Erlang and JavaScript runtimes it runs on are extremely mature and battle-tested. Gleam is ready for mission critical workloads.
What are Gleam programmers called?
Gleamlins, according to the Gleam Discord server.
Is it good?
Yes, I think so. :)