Gleam v1.9
240 points by lpil 4 months ago | 71 comments- trescenzi 4 months agoAs always Gleam’s lsp actions show just how much useful code generation can be done without the need for any gen ai so long as you have strong types. I continue to be amazed just how much the community cares about the developer experience of the language.
- giacomocava 4 months agoThe language server has been improving at such a fast pace it's hard to keep up! Soon I'll be out of code actions to implement
- giacomocava 4 months ago
- ThinkBeat 4 months agoI do not quite understand that it runs on BEAM and Javascript with runtime.
Most of the great things I like about Elixir is tied to feature native to BEAM. (I think).
And I would expect that BEAM has not been ported to a Javascript runtime?
I would also expect at Gleam for Javascript can use and interact with Javascript libraries and what not, not possible under the regular version.
I would also expect that it is possible to write useful code that mill work on both platforms. but with a lot of limitations.
Do I have this completely wrong?
- Hasnep 4 months agoMost Gleam code is backend agnostic, but code that does something BEAM specific like OTP or Erlang FFI is only available when targeting the BEAM and JS ffi is only available when targeting JS. You can also provide two implementations of a function, one for each backend if you want to target both.
- nesarkvechnep 4 months agoErlang FFI? Doesn’t the Erlang Virtual Machine run the Gleam code? How is calling Erlang functions FFI?
- Hasnep 4 months agoI just mean FFI in the general sense, that you're interfacing with a non-Gleam language. What's the word for that? Bindings?
I guess if you've transpiled Gleam to JS then is calling a JS function even FFI anymore?
- Hasnep 4 months ago
- nesarkvechnep 4 months ago
- pjmlp 4 months agoYeah this is one of the typical mistakes of guest languages, they start by offering something that the platform language is missing out on, and eventual in the pursue for greater mindstart try to expand elsewhere, however by doing so, they lose the capabilities that made the original target platform special, and eventually become their own thing, if they survive beyond the typical adoption curve.
- FireInsight 4 months agoIt's useful because you can write back-end and front-end code with the same language. Code sharing should work, as long as you don't use runtime-specific features blindly. All basic language features seem to work the same regardless of runtime.
- lpil 4 months agoYup that's right, you can't use Erlang code on JS runtimes or JS code on Erlang runtimes. Most library code doesn't use either, so it's usable on both.
Elixir is also quite a lovely language even when not using any BEAM specific functionality! I used it a lot for writing regular sequential programs.
- eyelidlessness 4 months agoI think it might help to start with a baseline assumption: newer high-ish level languages (or any such language looking to expand mindshare) will inevitably be asked “[how] can I run code written in this language in a browser?”
- victorbjorklund 4 months agoThe benefit is you can write JS by writing the same language as the rest of your app. I wish I could do that with Elixir. Not run the app on a javascript runtime but write frontend code that will transpile to JS.
- Hasnep 4 months ago
- tmountain 4 months agoFeels like Gleam is gaining a lot of steam and getting a lot of attention recently. It’s the language that I am most excited about right now. It’s hitting all the right notes.
- giacomocava 4 months agoAll the pain to get echo working was 100% worth it! What a great release
- cardanome 4 months agoThinking back on how Python 3 broke nearly all existing Python beginner code because they made print a function instead of a statement feels ironic now.
Sure print being a function has slight benefits in certain cases but the Gleam team also makes very compelling arguments to implement echo as a special keyword.
So what do we learn from that? Maybe don't do breaking changes to your language. Maybe debugging and actually printing should be separate things, one a statement, the other a function? I don't know.
- eyelidlessness 4 months agoI don’t know enough about Gleam’s implementation to say how applicable this is, but from a more general language design perspective… a keyword isn’t inherently imbued with special capabilities that a function call wouldn’t be. They’re semantically interchangeable for this use case, if the function can access requisite information about the underlying stack.
I’m not sure it’s possible to extrapolate any lessons for Python from this Gleam language feature or the chosen syntax.
- bobbylarrybobby 4 months agoThat's the problem though: I think the thing that makes functions functions it that they operate on values alone (whatever “value” means in the context of the language — but it almost certainly doesn't include code or AST or anything like that), and don't care about, or even get to see, the particular expression that produced a given value. The thing that makes statements (or macros, or various other compile-time stuff) not-functions is that they don't just have access to values, but to the code as well, which lets them do stuff like print the expression that produced a value, which a function could never do (in most languages; I'm sure there are some out there, maybe a LISP or something, that attach the AST to expressions as metadata).
- bobbylarrybobby 4 months ago
- eyelidlessness 4 months ago
- spinningslate 4 months agoAs a dyed-in-the-wool print debugging advocate, and a Gleam-curious Erlang/BEAM enthusiast, this is very interesting for me.
Thanks for all your work, great to see how well the language and tooling are maturing.
- giacomocava 4 months agoprint debugging is the best debugging <3 Thank you for the kind comment!!
- IshKebab 4 months agoNah it's just the easiest and most reliable way. Usually anyway; sometimes you have extreme timing or space constraints and can't even use that. On microcontrollers I sometimes have to resort to GPIO debug outputs and I've worked on USB audio drivers where printf isn't an option.
- IshKebab 4 months ago
- hayleighdotdev 4 months agohello fellow print debugging enjoyer, rejoice!
- reddit_clone 4 months agoIndeed, for me, the IDE debuggers became useless when we started writing multi threaded programs.
Printf is the only way to reliably debug multi threaded programs.
- reddit_clone 4 months ago
- giacomocava 4 months ago
- cardanome 4 months ago
- maleldil 4 months agoGleam looks like a really nice language that I haven't had a place to use yet. Does anyone have experience using it as a replacement/alternative for TypeScript for (e.g.) CLI tools?
- ivanjermakov 4 months agoWhat is the point of making echo a special syntax and not just a function? And add another function to retrieve stack info.
- gdotdesign 4 months agoThe compiler can inject information at compile time so no runtime reflection is necessary.
- wavemode 4 months agoWell, there's nothing stopping the language from having builtin functions and constants in the standard library that are handled specially by the compiler, the same way this echo keyword is. That would've had the added benefit of being backwards compatible (which new keywords are not).
- _danielle_ 4 months agoGleam reserved a handful of keywords in 1.0 (including echo), so it isn't a new keyword.
- lpil 4 months agoWhat you're describing is what `echo` is in terms of functionality and implemented, and it's not a new keyword so it is backwards compatible.
There are disadvantages of blurring the lines of what a function is an can do. Gleam values clarity above all things, so we don't have back-doors or special-cases. Everything plays by the same rules.
- keeganpoppen 4 months agothat is basically just a keyword with extra steps...
- _danielle_ 4 months ago
- ivanjermakov 4 months agoCall site can be inlined in compile time, without special syntax. Full stack trace would require runtime support anyway.
- wavemode 4 months ago
- gdotdesign 4 months ago
- akudha 4 months agoAs Elixir is getting its own type system, should one still pick Gleam over Elixir?
- hayleighdotdev 4 months agoThey're kind of solving different problems. It's a bit like TypeScript vs Elm or PureScript: one is a type system overlaid onto an existing language with its own rich ecosystem and set of idioms, and the other is a new language that targets the same underlying platform but has different idioms and semantics for static analysis.
If you already have lots of Elixir in production, or you enjoy Elixir's highly dynamic approach to solving problems and would like to get some additional safety for free then sticking with Elixir is a no-brainer!
If you'd like a simpler language with tighter static analysis guarantees while still being able to dip into the wider ecosystem then you might prefer Gleam.
Ultimately I think the two languages have very different philosophies and idioms, folks will naturally find themselves preferring one or the other ^.^
- tmountain 4 months agoGleam is about as simple as Go but with a more expressive type system and Elm style guarantees that your app won’t crash if you stay in its ecosystem.
- tmountain 4 months ago
- sodapopcan 4 months agoI'm not fully qualified but in a nutshell, Gleam doesn't support OTP out of the box. There is a separate package for it [0] but it doesn't offer everything, so it depends on your needs. If you're going to be doing heavy OTP stuff you'll need to stick with Elixir. If you want to transpile to JS, then Gleam is the better choice. Otherwise it's up to your tastes around type systems and syntax.
- lpil 4 months agoGleam isn't different from Erlang or Elixir in this case, all three languages implement OTP in "user land" rather than being part of the language. The only difference is how this OTP code gets distributed from the core team to you. In Gleam the BEAM ecosystem package manager is used, Elixir and Erlang leave it up to the operating system package manager, a docker container, or some other solution.
- sodapopcan 4 months ago> all three languages implement OTP in "user land" rather than being part of the language
I understand that, but why then is OTP then limited on Gleam? Is interop to Erlang different than it is in Elixir? Elixir doesn't offer Elixir versions of a *lot* of OTP, but its Erlang interop feels quite natural (though not seamless). Can you just farm out to Erlang in Gleam? Does Gleam's static typing hinder this at all? Of course I can look this up for myself, but figured I'd asked here for the benefit of others since you're the author of Gleam :)
- sodapopcan 4 months ago
- worthless-trash 4 months agoI've written OTP and distributed code using gleam. Type checking inter system messages was rough, but its not like it didnt work.
I have used gleam and my own FFI, calling erlang from gleam isn't difficult.
- lpil 4 months ago
- bmitc 4 months agoI find it unfortunate. The BEAM is so influential as a VM, that most languages on top of it will be very similar. I don't really like the situation where we have Erlang, Elixir, and Gleam all atop the same VM, and they're all basically the same language. It's a split that isn't needed.
- lpil 4 months agoHi, I'm the designer of Gleam!
Beyond being functional and sharing a runtime I don't think Elixir and Gleam have much in common at all. Our recent developer survey showed that the majority of Gleam programmers were not Elixir users and largely were not attracted to that language.
- bmitc 4 months agoMy question is: is how one approaches writing programs in Erlang, Elixir, and Gleam fundamentally different from one another? And is the difference enough for the split in the ecosystem?
> Our recent developer survey showed that the majority of Gleam programmers ... largely were not attracted to that language.
I must admit that I find that fairly bizarre. What do you imagine the source of that lack of desire is?
For context, my favorite language is F# and ML-dialects in general, but I also like what I call "principled" dynamically typed languages like Scheme, Racket, Erlang, and Elixir.
- bmitc 4 months ago
- tmountain 4 months agoThere are TONS of JVM languages and nobody is complaining about that. BEAM is much smaller and a very nice target IMO. I learned Erlang but found it too weird for my tastes. Elixir lacked a type system when I evaluated it, and that steered me away from it. Gleam feels kind of like Elm felt. Small, simple, and safe. It feels very intentional and designed for a particular purpose and audience. I did their online tutorial and felt comfortable with the language in one sitting. Can’t say that for many other languages.
- bmitc 4 months agoWho is choosing anything but Kotlin for new projects on the JVM?
The point is that beyond some basic typing things, programs written in Erlang, Elixir, and Gleam will all have the same core structure. Immutable data plus pattern matching plus BEAM processes has a pretty strong affect on any BEAM language.
- bmitc 4 months ago
- juped 4 months agoGleam is nothing like Erlang or Elixir (its copying of Rust is so slavish it even has a toml file driven build system) and Erlang and Elixir are not split (the only place where they even sorta are is rebar vs. mix).
I don't particularly want to gatekeep "Rust fans who just want to write lots of Rust" off OTP. Let them have Gleam. Maybe they'll figure out how to lifetime-annotate binaries?
- tomtheelder 4 months agoGleam and Rust are really not alike at all aside from the most superficial ways. A couple bits of syntax, and the use of toml are about all I can come up with.
- worthless-trash 4 months ago> Maybe they'll figure out how to lifetime-annotate binaries?
What do you mean by this, I know how lifetimes work in rust, but how would you do it on the binary level ?
- tomtheelder 4 months ago
- lpil 4 months ago
- hayleighdotdev 4 months ago
- fn-mote 4 months agoI tried to find out why I would try gleam, what I would use it for.
What I found convinced me it wasn’t for me.
1. Language behavior depends on the back end. Int doesn’t necessarily mean Int.
> When running on the Erlang virtual machine ints have no maximum and minimum size. When running on JavaScript runtimes ints are represented using JavaScript's 64 bit floating point numbers.
2. If it’s not an Int it’s a Float. Short numeric tower. I guess that’s ok. No BigInt with a guarantee it will not overflow? No exact Rational?
3. Type annotations [are optional and] “don’t change how the program runs”.
Ok this sounds like Python. Supposedly there are guarantees indicating “if it compiles it runs” but I’m worried. How do you even know the inferred type of your function is what you really think it should be? (I’m familiar with inference gone crazy from Haskell.)
- lpil 4 months agoIt's not anything like Python. The language that it is most like is probably F# or OCaml.
Python's type checkers are optional. They only verify code with annotations.
Gleam's type checker is mandatory, so it is impossible to compile code without type checking being performed. Type inference and checking are always fully performed, and adding type annotations doesn't make the compiler perform any extra checking.
> How do you even know the inferred type of your function is what you really think it should be? (I’m familiar with inference gone crazy from Haskell.)
Gleam doesn't have subtyping so this is typically trivial, but idiomatic code has all functions annotated for clarity. You can also hover in your editor, or read the documentation Gleam generates and publishes from code automatically.
- roetlich 4 months ago> How do you even know the inferred type of your function is what you really think it should be?
By adding a type annotation? Am I missing something?
- lpil 4 months ago
- shepherdjerred 4 months agoWhat's a good way to learn Gleam? In college I would learn new languages/libraries/concepts through projects, but these days I have too many projects already.
I don't expect I'll ever use Gleam at work, but the language does look very appealing to me and fun to use.
- mkcny 4 months agoGleam's interactive tour is a great place to start: https://tour.gleam.run/
There's also an Exercism track that has exercises contributed by Gleam's creator: https://exercism.org/tracks/gleam
- shepherdjerred 3 months agoJust wanted to thank you for this comment! I've been learning Gleam with Exercism and it's been so fun! It reminds me of when I was in college haha.
- shepherdjerred 3 months ago
- mkcny 4 months ago
- singularity2001 4 months agoWhatever happened to the Erlang wasm backend?
- mtndew4brkfst 4 months agoAre you thinking of this, formerly known as Lumen?
https://github.com/GetFirefly/firefly
AFAIK it's been mothballed and one of the major contributors seems to have left the BEAM ecosystem altogether. They're doing Ethereum-ish smart-contract-ish stuff now. The other top contributor looks to have pulled way back from OSS dev of any kind.
- mtndew4brkfst 4 months ago