Hacker News new | ask | show | jobs
Try Gleam (nchagnet.eu)
146 points by nchagnet 19 days ago
8 comments

I wrote this to show my appreciation of this small-ish but beautiful language.
Thanks! I really liked the concrete examples. Spending most of my days with the monster that is modern Swift, Gleam feels like fresh air.
I have a web app i've been using regularly and develop regularly with gleam on the frontend and backend. I have written very little of the code by hand and use claude to implement everything, open PRs and stuff and it works well. I like that it's typesafe and you can share code between the frontend and backend so easily, and you don't have to get a bunch of config right like you do if you want an all-typescript application. If I was writing it by hand I think I would find there's an annoying amount of boilerplate, but since ai is writing the code for me it's not a big deal.

Overall, I recommend it.

What framework did you use for Gleam? I feel the last time I looked that was one of the big absent libraries.
this is what grinds my gears with gleam. afaik its not really possible to interact with elixir libraries? A project exists to try to make this 'easier' but the fact that it was not baked-in as first class is a huge smell to me https://github.com/gleam-lang/mix_gleam/

Perfect example: Clojure. Clojure is the textbook esoteric programmers dream... but it's SUPER easy to sell and integrate in a typical Java shop. Why? Clojure is Java. You can use everything on Maven. You can interop with any Java tooling. No hacks or BS required... it's a native compatibility. The fact that the Gleam did not opt for this level of congruence is mind boggling to me.

I could be wrong btw so please correct me if I am. I am genuinely interested in using Gleam in place of Elixir (I think they nailed syntax and got rid of a lot of bullshit) but it is unfortunately not a drop-in replacement. It should be.

There are two sides to compatibility with Elixir: using Gleam in Elixir and using Elixir in Gleam. The former is harder, the latter is easier (with caveats).

Using Gleam in an Elixir project did/does rely on mix_gleam. I've used it some years ago and it worked then, but I haven't had recent experiences. There is a pull request[0] to Elixir to add built-in support for Gleam and as I understand it the Gleam team have made several changes to Gleam tooling to facilitate it, but it's unmerged as of now.

Using Elixir in a Gleam project is just an external function away, just like using Erlang or JavaScript (when using the JS target). E.g.

  @external(erlang, "Elixir.Some.Module", "my_fun")
  fn my_fun(some_arg: Wibble) -> Wobble
You can also write .ex files in your codebase and use functions from them as externals and they'll be compiled by Gleam.

The two main issues on that side are macros and structs. Since Gleam doesn't know about Elixir source or Elixir macros, you can't use them directly. But you can have an .ex file that uses macros and then you can call functions from that file. Structs are trickier, because they're just dynamic maps with a special key-value pair, and maps in Gleam (called Dict) have fixed types for the keys and values. That means you can't model a struct as a Dict. Gleam uses records for its own custom types, so what you can do is either use records on the Elixir side (with the Record module or by hand), or map the Elixir side data structures to be more palatable for Gleam (and vice versa) in your external functions --- which is what you generally do with externals anyway. Of course, if you only intend to pass the Elixir structs around and then back to Elixir, you can model them as external types that are then opaque to Gleam.

[0] https://github.com/elixir-lang/elixir/pull/14262

https://github.com/lustre-labs/lustre for the frontend. The backend uses wisp
if the ai is writing everything wouldn't it be better to choose a more popular language?
Exactly the opposite -- in a lot of ways, mainstream languages represent a compromise that gives the worst of all worlds for the benefit of popularity. With AI, you can take advantage of unpopular esoteric languages that have measurable advantages over mainstream languages. Before, the choice for a mainstream language was too strong because of network effects. Now with AI those effects don't matter as much, so being mainstream isn't as much of an advantage.

The copious training data on mainstream languages doesn't really translate as a network effect, and therefore is kind of a red herring because the AI can use all that training on new languages as well. e.g. if you use a esoteric language that is vaguely object oriented, the AI will use its vast training on object oriented programs and apply it to your language instead of falling over because your language isn't Python and it doesn't have training data on it.

Moreover, the AI is trained on copious amounts of PL research, so it's not like the ideas in a new language are completely new to it.

Another BEAM-based language, Elixir, came in first in a recent agentic coding study: https://dashbit.co/blog/why-elixir-best-language-for-ai
In that Tencent study less common languages got easier problems. Which explains why racket also performed suspiciously well in it. The authors recognize the problem themselves. I like elixir, but it's imo embarrassing how often elixir people cite that study despite it not actually supporting what they claim.

A much more recent and imo more realistic comparison of different languages with ai, is openai's study reimplementing sqlite in different languages: https://openai.com/index/low-resource-programming-languages/

That showed about what we expect, that popular languages like python, javascript, java, C#, etc do best, while less popular languages like Common Lisp, Ocaml, Zig, etc do slightly worse. But the difference is small enough I'd still just choose whatever language and ecosystem I know best that is appropriate for a project.

What they did is they gave the AI a huge pile of docs and said "implement this". But they didn't give the AI any tests as part of its objective. I was under the impression it's generally common practice to use a test-driven development approach with AI, so I think it would have been more representative for them to have split their test corpus in half: one half it could see during implementation, and then the could test on the other half.

Also, they restricted access from the internet, so I think this would have disadvantaged less popular languages.

I would definitely be skeptical of a study that finds using an LLM/agent to write sqlite in JS being better than writing in Zig, but it strongly depends on what “better” or “worse” mean.
It means how much of the sqlite test suite it passed. They were just measuring correctness, not performance or memory consumption, where of course Zig should win.

But the aim of that experiment was measuring correctness of llm written code in different languages, so used sqlite as a benchmark considering it's fairly complex software with a comprehensive test suite. It is not suggesting that because a language scores better on that benchmark it'd be better suited to writing the next sqlite, due to obvious other factors like performance...

A more popular language like what? The more popular choice that I could think of was typescript and the world around typescript and javascript is so big and fragmented I think you'd end up with it the ai doing things in different ways in different places. Gleam is a smaller ecosystem but it also just feels better organized and more consistent which helps for keeping things consistent in your app.
Why's that?
Lots and lots of production code to train AI models.
That mindset is a bit dated when models can pull up docs for a few years now. You can even have it write itself a little guide for lesser known languages within its own agents file.
Programming models have been sophisticated enough for some time to not be restricted to specific languages. It's rather like the difference between a junior developer (who knows how to use a specific language) and a mid developer (who knows who to program generally).
Thanks for creating Gleam!

Is there any research that supports what you are saying here? I agree it mostly works, but I’d expect more API hallucinations and test cycles at a minimum.

The entire gleam language tour fits comfortably in a modern LLM context window. You're one web search away from "training" it yourself.
I'm not sure how much that matters. I suspect and anecdotally hear/see that compiler errors and docs are as/more important.
Too much schlock in the manifold, IMHO.
What's the fuckin point of any language ergonomic if you're not reading or writing it.
Not sure why you're asking this? But i mean if a language is more readable and has good typesafety it's easier for llms to understand, plus a lot of times you want to read and understand it even if you're not typing it out yourself
More ergonomic languages burn fewer LLM tokens to get the same result.
That's also not true at all. The most efficient languages for an LLM are the ones that have the largest datasets to reference. It knows the shape of a billion lines of Python. There's no evidence to suggest that "a more ergonomic language" burns less tokens cause it probably has to do multiple sweeps to get it "right". Otherwise some "agent/token efficient" language would've already been built and we'd all be using it. The defacto are just the most popular languages and that's not a coincidence.
Only if they gain that ergonomic advantage without complicating flow of control. Metaprogramming is costly for example, in the past so have been operator overloading and lazy evaluation.
Had a great talk on Gleam at the Carolina Code Conference a couple of years ago by Dillon Mulroy, now with Cloudflare I believe.

https://carolina.codes/speakers/2024/dillon-mulroy

That site is also partially powered by Gleam on the backend.

Was in person for this talk! Dillon did a great job, obviously passionate about the language and its ecosystem.
Gleam is really a delightful language with great ideas, but the lack of currying is a tragedy.

Missing currying feels a little to me like walking in FP land with one leg cut off.

I never liked currying. It feels more theoretically elegant than practically useful.

IMO it is hard to read (unless you're very familiar with the functions at hand), produces type errors that are not easy to follow (oops, I forgot the last arg), and is too rigid (I often need to partially apply arguments in non left-to-right order).

I never understood why partial application via "slots" isn't more common though (I just made up the term, not sure if this has a name). Like Clojure's:

    #(f %2 "foo" %1 "bar")
    ;; same as
    (fn [a b] (f b "foo" a "bar"))
Does Gleam have something like that?
Yes Gleam allows you to do f(arg, _)

See the relevant docs: https://tour.gleam.run/everything/#functions-function-captur...

But that's a single argument right?

Seems more limiting than the closure way. Scala allows multiple _ but in turn that doesn't allow changing ordering.

TBH, I feel this stuff is not really worth it,

I think the single hole version is a good compromise compared to actual currying or multiple holes, since it's strictly better than something like first or last argument threading (e.g. ->, ->> in Clojure), easier to reason about than currying, and in my experience most of the time you'll only be dealing with one argument to pass piping anyway. Anonymous functions are fine for the cases you need more flexibility.
Are there any physicists out there who are reminded of abstract index notation for tensors?
A deal breaker, and just when I was starting to get excited!

Plenty of practical reasons for currying, but the biggest (imo) is for use with the pipe operator.

If they don't have partial application now, what are the odds they'll have it in the future?

As I mentioned in my other comment, they do have partial application with _, and it works like a charm for piping! It's automatic currying which is absent.
And that's fine, because currying forces you into impossible tradeoffs when choosing argument order.
Ymmv, but you can get pretty far with a convention: order arguments by _how likely they are to be closed_ within any given context. As a full-time F# developer that covered >95% of what we were doing.

An alternative is providing variations on a function that "bundle" sets of arguments, and then making the bundle the first parameter, but that only makes sense when the "bundles" occur together a lot.

I would rather see syntax to make partial application on arbitrary named or positional slots as ergonomic as possible. How much has that been explored by existing languages?
But Haskell has nice little functions for switching argument order, and people can easily make them in other currying languages.
Apart from the language, what's the developer experience like, especially doing full-stack?

F# showed a lot of promise with Fable, but the community never quite got the tooling right, I think for a lack of energy/funding.

I found the tooling to be quite comprehensive, the LSP is high-quality for a small project.

There are a few rough patches too. For example, I have yet to find out how to run a single test and not the whole suite.

Tangent: the correct approach looks like filtering the suite down to a single test rather than running individual tests independently.
I've been keen to try it out for a while, I might do something with it in the near future.
To your point on "Gleam: the bad" and the ecosystem being small, I would add that this community has a history of activism behaviour. Some like that, I'm out.
> Some like that, I'm out.

And a third group couldn't care less either way.

I have a few decades on my back, I am a father, a husband, a nerd... I once was young too, believe it or not, and I had ideals and I fought for them.

If you don't participate in this, why does it bother you? Unless they are active around your doorstep, that is.

Fair point, I am with you on that. I guess just had a bad first impression on drama that I've seen as a spectator through the public channels that stuck.

That could be repaired, just don't care enough to spend time there again I guess.

Couldn't agree more with this. Having ideals and principles isn't a bad thing, we all do.
I for one am thankful for their warning. Saved me precious time.

Suggestions about cool projects are just as important as warnings about uncool projects.

Yes, it's just that I don't deem them uncool.

Same as art by Hitler... if I would like it, I would like it, doesn't matter that I think he was one of the worst human beings.

So: I just argued, that there is a third way to view it.

You may, of course, see it completely differently and deem this project "uncool" for whatever reasons you want!

What kind of activism? Isn't activism just "doing something to try and make a larger change"?
Does "larger [political] change" need to run sidecar to a programming language?
I wasn't particularly aware of that to be honest. What kind?
I saw a thread once from the language creator and community owner that left an impression on me https://news.ycombinator.com/item?id=46614727
Wait, people are upset because they have a code of conduct?
People are upset because their "code of conduct" extends far beyond the reasonable purview of the project.

You may not participate if you hold and espouse ideals contrary to theirs in unrelated spaces.

Read the CoC again: https://github.com/gleam-lang/gleam/blob/main/CODE_OF_CONDUC...

It doesn't police peoples' personal beliefs outside the community. It only says that while participating in the community you agree not to harass people and try to contribute in a positive way.

I wonder if you have past experiences that are coloring your interpretation of this, because I'm really unsure where you're getting any of this from.

What does the code of conduct say?

I didn’t see a link to it.

Where is the "activism behavior"? All I see in the thread is other people whining because they disagree with the Gleam community's values.
Agreed. Treat people well seemed to be the Gleam desire.

The counterarguments from the other party (seemed like one person with multiple accounts to me) were about their disbelief in trans people and the idea behind the Black Lives Matter movement (coupling it with some organization that copied the name and stole some donations)

Couldn't find it either, and my experience with the gleam community is that they're very welcoming and positive people.
I am on that thread as well. The issue with these "codes of conduct" isn't that they exist, it's that their purveyors force the "code" upon every participant regardless of forum.

If you don't support their special interests in completely unrelated venues, you are persona non grata and will either fall in line or be excommunicated. It's a sophisticated form of control via identity politics.

I think you're seriously overreacting; you don't need to believe the same things that they do, all the CoC states is that if you want to engage with the community, you agree not to harass people. Every community has similar expectations; having it in a markdown just makes it more explicit.
I... Think many of us would like evidence to back this up. Can you demonstrate that the Gleam community has done this, specifically? Because it really seems, to me at least, that this is a bit of straw-manning.
I mean, yeah — people won't want to be in community with someone who transgresses against their social norms and values. Freely choosing with whom you associate is not a "form of control". You're still welcome to use the project.
Sounds to me like a lot of divisive American politics, as usual.

I have no problem with a community setting whatever acceptance criteria they like.

If the license did the same, I could see a case of being a bit of overzealousness.

I couldn't find if that was the issue, but if your problem is that the creator and the community have political opinions and don't like people with incompatible ones, then that's just society...

> but if your problem is that the creator and the community have political opinions and don't like people with incompatible ones, then that's just society...

No, I am fine with incompatible views and I often seek them in order to grow. I do not enjoy echo chambers and I usually prefer and welcome disparate, including contrarian, opinions.

It's more like I don't want Ideology served with Programming Language, it feels like a distraction to me when I am in that mode. I usually consume Ideology under a different context, where I find it more productive and can contribute better to it.

I think you have a reasonable position here, so I understand where you come from.

I find this whole thread here interesting because until today I wasn't confronted by any of this, even though I joined the Discord and had a pleasant time (and will keep doing).

So I guess all I have to say on this is I don't think the "ideology" is that much served with the programming language. Yes I read that there's a code of conduct and that annoyed some people. But like I downloaded Gleam, I coded with it, I talked to people, and the thought police didn't knock on my door. So I guess what I mean is that it feels a little overblown.

> creator and the community have political opinions and don't like people with incompatible ones, then that's just society

Why are my political views relevant? This is a programming language. Nobody is popping into the Gleam issue tracker and mentioning politics, nobody is violating the "code of conduct" there.

The "code of conduct" exists solely to lambast people who disagree with the author's special interests in other irrelevant spaces. This is the "paradox of tolerance" in codified form.

I mean it's only relevant if you bring it with you in their community. You don't sign your soul away when you download the compiler. Do you have the same issue with all the ToS asking you to not be a nazi and whatnot on a given platform?
Maybe you could be specific, instead of just spreading FUD? I read through the discussion you linked, and I have no idea what you’re talking about, so to me your comment comes of as just FUD.
On the Gleam homepage under the Friendly heading it says “Black lives matter. Trans rights are human rights. No nazi bullsh*t.”

That’s probably what the OP meant by “activism”.

https://gleam.run/

I don’t have a problem with activism per se, but it does put me off how the official website tries to make the language and community look extremely friendly and cutesy, only to immediately break that facade. If that’s the look you’ve decided to go for, at least try and commit to it!
You know you don't need to follow hold their CoC in any way to use the language right?

Do you only use languages that you can contribute to their codebase?

"Contribute to their codebase" includes bug reports and seeking help with errata and other issues.

It might be problematic to use a language where needed help could be preceded by Twitter or HN background and allegiance check.

> "Contribute to their codebase" includes bug reports and seeking help with errata and other issues.

That is exceedingly rare. The vast majority of times you will either find your answer online to work your way around issues.

> It might be problematic to use a language where needed help could be preceded by Twitter or HN background and allegiance check.

I would remind you that we have LLMs now. One of the greatest gifts of LLMs is not having to rely on talking to people online to figure out issues when using a language/framework/library.

Both searching for answers online and consulting LLM’s depends on prior human works or interactions, and (from what I know) their feasibility scales with the language’s popularity. I should expect both approaches to work much more reliably for Perl or Python than they would for Gleam or Newlisp.
opensource is activism
Hey! I know this!