10 ms·
Gleam: A statically typed language for the Erlang VM
- eggy 7y agoI'm interested in Erlang, since I first heard about it when I wanted to write plugins or work on the Wings3D program back in 2003 or 2004. I chose playing with LFE over Elixir, because I prefer Lisp syntax to Ruby-like syntax, but limitations of the BEAM, and core have some gotchas for running a Lisp. I'd like to try Gleam. It looks clean, and I like the fact that it is typed. The Erlang/OTP and other BEAM languages work well for what they are intended for, but if you do any number crunching they are slow. The Elixir/Phoenix stack seems to be a great combo for web developers. I'll give it a try by compiling it on my Windows box with Rust, since my iMac Pro 27 is mid-2011, and my Linux notebook is busy right now for other jobs.
- lpil 7y agoHi, I'm the author of Gleam. Thanks for giving it a try! Rust compilation can be very slow, so we provide pre-compiled binaries for common platform. See the website and the releases page for more information: https://gleam.run/getting-started/installing-gleam.html https://gleam.run/getting-started/installing-gleam.html https://github.com/gleam-lang/gleam/releases https://github.com/gleam-lang/gleam/releases
- eggy 7y agoThanks! I only saw Mac and Linux on the installation page. Nice to see the windows binary on the releases page. I have all three systems, but my windows box is my main go to, and my newest and most powerful laptop. I'll try it after work tonight, and get back to you with any questions. Is there a forum, or just use Github?
- dnautics 7y ago> The Elixir/Phoenix stack seems to be a great combo for web developers. It's a great combo for more than that. I'm building a vm orchestrator on top of it and couldn't be happier (does everything from DHCP serving to virtualization library binding and resource matching). I do happen to have Phoenix in there, but it's for an entirely optional operator dashboard.
- toast0 7y agoIs your orchestrator public? I think this is a great niche for BEAM and would love to see what it looks like.
- dnautics 7y agoIt's not, sorry. There's a lot of security-related things that are still hard-coded that will take some effort to decouple, but I am working towards that. But I've open sourced a few low-level bits of it, like dhcp, tftp, a few still-experimental inter-controller transport protocols, and they're available on hex (but not virtualization yet, but probably by the end of the year). There's a few things like "building vm images", "provisioning host images" that might come in soon. But also we're hiring, so if you're available and interested in seeing the product, drop a line!
- eggy 7y agoIs Phoenix only for the optional operator dashboard? I ask because I have not tried Phoenix. I've played with Elixir since it came out, but only Elixir.
- dnautics 7y agoyep, although I am working on rewriting the user frontend in Phoenix, that is a political hurdle to get out into the wild. Most people learn Phoenix, then elixir, but I also learned Elixir, then Phoenix, and I think it gives me a stronger handle on how the VM works under the hood.
- MrLeap 7y agoForgive me, I'm ignorant -- what's erlang for. "Concurrent applications" is the raison d'etre I see espoused. What's that mean? Does it make concurrent applications easier to write? Does it make it easier to use the SIMD instruction set, how hard is it to get a function written in erlang to run on a gpu? Is it like nodejs but more performant? I appreciate anyone who has answers here, I try to position all the relatively interesting things I don't have much time to dive in to in a mental model with opportunities for future promotion.
- lliamander 7y agoFair Question! It's not a language oriented at maximum throughput of parallel operations. It is a language that is oriented at providing very low latency (soft real-time) handling of lots of events. When you write in Erlang, you decompose your program into lots (think upwards of millions) of small user-space processes, that communicate using asynchronous messages. One side-effect of this architecture is that your application will scale in performance as you add more cores without having to change the code. It's a great language for server applications, like NodeJS. It also has a number of features that make it great for embedded and IoT type applications (which is why it was created in the first place).
- deleted 7y ago[deleted]
- zelphirkalt 7y agoAfaik, Erlang is all about that actor model, message passing and abstracting the lower levels away, so that ideally does not even notice that an actor is running on another machine. All of that of course with automatic restarting of failed actors. Basically it is Kubernetes done right and probably has way more functionality, as it predates all the Kubernetes stuff by a long shot and development hasn't stopped.
- deleted 7y ago[deleted]
- mrkeen 7y ago
- salimmadjd 7y agoLooks interesting. I only wish it used Haskell's type annotation. I've been learning Haskell recently and I'm really liking how easy it is to read and digest codes. I feel like Haskell in general is yielding much cleaner code and once you start learning it, so much easier to follow the logic of a code and not get lost in all the noodles of commas, parentheses and unneeded brackets.
- lpil 7y agoHi! I'm the author of Gleam! Originally Gleam had a more Haskell-like (or rather a more OCaml-like) syntax. Over time people generally expressed a preference for a more familiar C-like syntax, citing the unfamiliar syntax making it seem unapproachable. Originally I thought these thoughts on syntax were unimportant (after all, syntax doesn't really matter) but after looking at the success of ReasonML (an alternative syntax for OCaml) and how it brought FP to a much wider audience, I decided that it would make sense to use this more C style syntax. Gleam aims to be very accessible and welcoming to as many people as possible, so in this area we've gone for something I personally prefer less as it it may help others more.
- eggy 7y agoIt's why I am learning Zig instead of Rust really. I think it is more like C, and is a lot less to bite off. Probably a wise choice for Gleam, but I do like Haskell/Idris syntax too wrt to types.
- lpil 7y agoThere is quite a learning curl on Rust, for sure! I was always more of a Haskell user and had little C experience, so I found Rust a good fit for me. The type systems are quite similar :)
- sbarre 7y agoFor someone who is unfamiliar with ML-type languages, can you summarize some good use-cases for Gleam? i.e. why would I learn and/or use this language? Or is that too open-ended a question? I work with Elixir so I'm a big BEAM/OTP proponent, so I am curious to know about Gleam..
- qchris 7y agoAs someone familiar with Rust who has been interested in Erlang/Elixir, but hasn't taken the plunge, this could offer an really nice compromise for helping to learn without necessarily needing to start from scratch. It definitely seems worth keeping an eye on! Also, as an aside, I have to say that I'm a big fan of the proliferation of educational documentation written using the mdbook format. Since the compiler is written in Rust, I'd imagine that's where the author drew some inspiration from (much of Rust's documentation is written using that same format). It's easy to navigate, the code blocks render nicely, and I generally just find it pleasant to read.
- lpil 7y agoThank you for the kind words! I hope in future we will fit that niche nicely :)
- epelesis 7y agoThe guy [1] who runs this project is super nice, about a year ago I was working on my own Rust based VM and he dropped in with a couple of helpful tips and ideas. [1]: https://github.com/lpil https://github.com/lpil
- lpil 7y ago<3
- adamcharnock 7y agoI can absolutely confirm this. A wonderful combination of patient, kind, and super-knowledgeable. He was a very good sounding board in the early days of one of my projects.
- lpil 7y agoThank you Adam! <3
- VWWHFSfQ 7y agoThis looks very interesting. Saved.
- ProfHewitt 7y agoFor those interested in the underlying theory of Actors see the following: Information Security Requires Strongly-Typed Actors and Theories https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3418003 Physical Indeterminacy in Digital Computation https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3459566
- eterm 7y agoA little while ago I saw a conference talk about gleam. [1] It was my favourite talk of the conference outside the keynotes. The first ten minutes is a good high level introduction to erlang itself. I've been meaning to check gleam out since, this HN post has served as a good reminder to do so. [1] https://www.youtube.com/watch?v=HaKR2kt-DXI https://www.youtube.com/watch?v=HaKR2kt-DXI
- lpil 7y agoThank you so much! I was pretty nervous seeing as Code Mesh is my favourite coherence. I'm really glad you enjoyed it :)
- aabbcc1241 7y agoNot sure about IDE integration but the language looks nice. Having a typed language makes me reconsider using the beam in my next project !
- lpil 7y agoLSP support is on the backlog. Having world class IDR features in all editors is an important part of the puzzle in my opinion.
- HorkHunter 7y agoI'm really happy the Erlang and BEAM are finally getting the attention / traction they deserve! the language was kind of underappreciated or considered very niche for a long time
- macintux 7y agoI came to Erlang (and HN) after this time period, but apparently there was a period during which the language appeared on the HN front page a ridiculous amount, sometime around 2010 perhaps? With the rise of Elixir it’s been getting a fairly steady stream of mentions here.
- HorkHunter 7y agoI'm starting to see the recent interest as well, which I just wanted to complement. I've made myself familiar with Erlang around 2011/2012? encouraged by the writing this amazing book [1]. which is still around and super amazing fast introduction IMHO. unfortunately I have never implemented anything of significance with it. maybe its time :) [1]: https://learnyousomeerlang.com https://learnyousomeerlang.com
- lpil 7y agoThis is the book I learnt Erlang with! If it didn't exist Gleam probably wouldn't either.
- lpil 7y agoYou've found it :) This library is also worth looking at: https://github.com/gleam-experiments/otp_agent https://github.com/gleam-experiments/otp_agent
- mshockwave 7y agoA little disappoint that it doesn't have message passing, one of the most powerful weapons of the Erlang family. But the language looks clean and neat. I can understand it within couple of minutes
- macintux 7y agoPeople have been trying for, IIRC, 15+ years to add a full-fledged type system to Erlang, and the distributed nature keeps defeating them. This problem may never be solved.
- brightball 7y agoAt some point, I think it has to be accepted in the same way that we accept that REST APIs aren’t typed.
- virtualwhys 7y agoSee Akka Typed (based on the Actor model) for an example of typed message passing in a distributed system. Not sure what compromises were made, but it was a sore point for users of the library for years to throw around untyped messages when the host language (Scala) provided such a powerful type system.
- lpil 7y agoAkka Typed is not capable of expressing everything Erlang's OTP commonly does I'm afraid, so it's not a complete solution here. We do however have typed message passing libraries in Gleam that are in part inspired by Akka Typed.
- maxmcd 7y agoThere seems to be some work on that here: https://github.com/gleam-experiments/otp_process https://github.com/gleam-experiments/otp_process
- lpil 7y agoIt does have message passing, just implemented as a library rather then as a core language feature.
- cinnamonheart 7y agoThis is really neat! Have you considered an ML-like module system, with functors and such? I'd be curious if they could be connected with Erlang's processes somehow :)
- lpil 7y agoAt present we do not have a module + functor system as it does not mesh well with the compilation model of Erlang. I am interested in having a feature like this but there is much work and research to be done first.
- akst 7y agoNice! I’d imagine this is a much nicer experience than dialyzer. If the author is reading is it possible to type message passing / processes? I couldn’t see this in the docs but i may have missed it
- macintux 7y agoIt’s not. https://gleam.run/faqs.html#how-is-message-passing-typed https://gleam.run/faqs.html#how-is-message-passing-typed
- lpil 7y agoIt's not supported in the core language but we have some type safe bindings to messages and message passing as libraries. We may upgrade these to being part of the language itself but I don't want to rush this and get stuck with a sub-optimal design.
- mtarnovan 7y agoThis is a very interesting project, thanks. I'd love to see how you solve the problem of typed message passing in the language itself.
- lpil 7y agoThese two libraries are probably the best to look at: https://github.com/gleam-experiments/otp_agent https://github.com/gleam-experiments/otp_agent https://github.com/gleam-experiments/otp_process https://github.com/gleam-experiments/otp_process They could be improved but they are good enough for us to get started with.
- YorickPeterse 7y agoType safe process communication is a tough nut to crack. You can sort of handle it by doing away with PIDs or by at least making them generic, but that leaves out corner cases such as sending a message to the current process. Type inference of the message types is also hard, imagine something like this (using pseudo code here): let pid = spawn { ... hundreds of lines of code ... let message = receive message + 10 } ... lots of code here ... send(pid, 20) A compiler being able to infer the type of the message here will depend a bit on how it processes code: does it go into the spawn first, or process that later? If it does go into spawn first, what should it do when it reaches `message + 10`. And what if we were to process `send()` first, but it's actually sending the wrong type? We'd probably infer the type to be an integer, even if the receiving end actually wanted something else. Session types are one approach to dealing with this, but I have yet to see an implementation of this where it's actually pleasant to describe the session in the type system; most that I remember turn out horribly complex. I spent a fair bit of time on this for Inko (https://inko-lang.org/ https://inko-lang.org/) as it has a similar message sending system. Right now you'd have to use pattern matching to make things safe (this isn't released yet), but obviously I would like to check this at compile-time. Sadly I haven't been able to make this work yet, as there was always some corner case somewhere that meant that whatever I had implemented at that point wouldn't quite cut it. For a while Inko had a special API for this that basically worked by sending types closures to the receiving end, that way type-safety could be enforced by making sure the right closures were used. Sadly this is not the most efficient, and in some cases still required type annotations. One thing I did, but this may not work for Gleam, is to replace PIDs with just references to processes, and only allow obtaining such references by spawning a process. By not allowing one to just create a PID out of thin air, you reduce the likelihood of a process randomly receiving a message of a type it does not understand. A side benefit of this is not having to allocate PIDs, which I found out can actually be quite a bottleneck when spawning many processes (though Gleam being based on BEAM has no real choice in this matter).
- dang 7y agoA related article from last year: https://notamonadtutorial.com/an-interview-with-the-creator-of-gleam-an-ml-like-language-for-the-erlang-vm-with-a-compiler-e94775f60dc7 https://notamonadtutorial.com/an-interview-with-the-creator-... via https://news.ycombinator.com/item?id=19547418 https://news.ycombinator.com/item?id=19547418 (but no comments there)
- lelf 7y agoSee also: https://github.com/purerl/purerl https://github.com/purerl/purerl, an Erlang backend for PureScript, which is a lot more mature but unfortunately doesn't get the attention it deserves.
- adelarsq 7y agoNice. Didn't know. Which tools are better to work with this?
- lpil 7y agoWhat do you mean by tools? :)
- lpil 7y agoA really cool project, and the people involved are really cool too!
- sharno 7y agoHave seen that Purerl is actually used in production in some companies. It's amazing to see how Purescript being used more
- msie 7y agoWow! So far this looks like the language I wanted to make! I wanted something like Elixir but with type declarations being part of the language as opposed to being annotations. I’ll be looking at this all weekend! It’s got the right ergonomics.
- lpil 7y agoThank you! Let us know if you have any feedback.
- anarchyrucks 7y agoYou might want to check Inko[0] out. It is still in alpha stage of development so you can probably contribute to it as well. Inko is a gradually typed, OOP language which uses erlang like isolated processes that don't share memory for concurrency.
- rajeshrajappan 7y agolpil is super smart and generally an awesome guy. I worked with him at a startup and learned a lot from him.
- lpil 7y agoThank you Raj, you're pretty great yourself!
- 1propionyl 7y agoIs it just me or does the introduction not mention equivalents to Erlang's messaging operators, or how to use OTP at all? Or _anything_ about proceses at all!? I feel like this is Rust syntax on top of beam... but seems to be missing the point of Erlang.
- lpil 7y agoThe website current is an introduction to just the language itself. Later we have detailed documentation on the subject of OTP, but there is a lot of work to do first. Gleam is a very young language. As a keen Erlang programmer I assure you that Gleam will do its best to make full use of the runtime's fantastic properties :)
- carlmr 7y agoAmazing. Adding the ability to do type driven design on top of the fault tolerance features of Erlang will make it easier to create correct AND fault tolerant applications. Let it fail, but not when you already know at compile time that it's wrong.
- Karupan 7y agoDumb question from a non Erlang person - can this be used along with Elixir? I’m looking at Phoenix LiveView but would love to use Gleam for core functionality. Is this anything like Scala/Clojure and compiles down to Erlang, I’m guessing that is possible?
- lpil 7y agoYes, it can be used with Elixir. We don't yet have any integration with mix (the Elixir build tool) so if I were to use both in the same project I would probably create an umbrella style application with one Elixir application and one Gleam application within it.
- lpil 7y agoAlso, I don't think that's a dumb question! Gleam does compile to Erlang, yes.
- virtualwhys 7y agoNot an Erlang user, but I must say the syntax is beautiful. I know, semantics before syntax, but if you can have both, why not? Looks promising, love the ML-style pattern matching in particular, so clean and terse (wish Scala 3 would ditch the `case` keyword in match statements, but alas not happening)
- lpil 7y agoThank you! I'm glad you like the syntax!
- zerr 7y agoAny plans for self-hosting?
- lpil 7y agoNot at present, though it would be nice to be able to do that one day. It would be largely a vanity project so I don't intend to spend time on it when we could be building more useful things.
- mstade 7y agoLooks interesting and quite approachable for someone familiar with C-style syntax. I was looking through the language tour and it's nice and succinct. A few things that came to mind: 1. Can multiline strings be indented, with the indentation stripped out? 2. Why do floats have their own operators? 3. What's the rationale for lists and tuples being different, and not just allowing lists to include different types? 4. How are module paths resolved? 5. Pattern matching looks great! 6. Function argument labeling looks great, I wish all languages did this! 7. Type system looks simple but capable, but in the User example it looks like the LoggedIn constructor isn't namespaced to User, so what happens if another type has the same constructor name? Conflict? On the same note, can you extend custom types after declaration, by adding constructors? (A little like Clojure protocols) 8. Can functions be overloaded, so you can provide multiple implementations for different argument signatures? 9. Can you implement custom operators, so you can for example `+` custom types together? Looks like a really nice language and I'm looking forward to trying it, but like others have mentioned I too miss the concurrency aspects given it's built on Erlang. Big kudos for including interop details in the docs right off the bat though, this is a big plus in the feature basket! Great work, definitely going to follow this!
- ivanbakel 7y ago>What's the rationale for lists and tuples being different, and not just allowing lists to include different types? Heterogeneous lists are a pretty advanced feature in the world of static typing. Since hetlists normally have to be fixed size anyways to do type-safe indexing, tuples are good enough for something like 99% of use cases.
- AlchemistCamp 7y agoIn Erlang, lists are linked lists. The fact that tuples are stored in memory sequentially is a major difference from lists.
- lpil 7y agoWhat data structure would you think of when you hear just "list"?