Hacker News new | past | comments | ask | show | jobs | submit login

It’s a nice language, and I like Lustre, but `use` is truly ugly.

I don’t understand why they didn’t make promises a first class citizen and added something like `await`. We’ve learned this lesson in JS already.




Can you explain why you don't like `use` but you would like an `await` keyword?

As far as I can see, `use` is a superset of the `await` transformation that just happens to work in a lot more situations. It circumvents callback hell when you're working on the Javascript target [1] but also de-indents lots of other code like handling results [2].

[1] https://github.com/gleam-lang/javascript [2] https://erikarow.land/notes/using-use-gleam


Your complaint doesn't make sense to me because `use` is essentially the same thing as `await` in JS. It hoists the rest of the function body into a callback so that the logic can be flat. In fact, `use` is an improvement on `await` because it is more generic and avoids the issue of function coloring. Promises also don't make as much sense in BEAM languages where callback based asynchronous code is not all that common or encouraged.


I'm still learning Gleam, but I do not believe that "use" has anything to do with async. It seems to be a direct riff on Haskell's "do notation" syntax sugar (<-), which is used for unwrapping monads, but Gleam seems keen on insulating users from these details at the surface level.

The author of the article has an intuition that "use" is helpful for error handling, and it definitely is because one of the core benefits of monads is chaining certain categories with a guarantee that nothing will blow up in the process; however, use cases are broader, as you can chain all sorts of things.

Looking at it now, it's actually akin to clojure's threading operator, which basically just simplifies syntax when making successive function calls (argument threading). Whatever the case, it's not just for errors/async, but more so for chaining without causing a bunch of unnecessary indents to occur.


Hello! I'm the creator of Gleam.

> It seems to be a direct riff on Haskell's "do notation" syntax sugar

It's not this at all! It may seem this way at first as Gleam's `use` is used in many of the same places as Haskell's `do`, but `use` is a much more general syntax which is used for a much wider array of things. They also work very differently, `do` being constrained by types and laws, while `use` being purely a syntactic feature with no type restrictions or laws.


Wow, thanks for the reply, and correction! I look forward to learning more about Gleam, as I've just started with it, and I'm really enjoying it so far.


Thank you, very kind!


I've written a fair amount of Gleam for personal projects at this point and I actually really like `use` when the alternative is excessive indentation / callback hell. That said, I do feel like its existence is a bit contradictory to the language's stated goal of simplicity; `use` is not an orthogonal feature, and I could see it being the subject of much bike-shedding in a team setting.

Languages that have explicit goals of simplicity, like Go, have become increasingly attractive to me after working professionally with Scala for the past 3 years. Though I love Scala's expressiveness, the fact that there are a million ways to accomplish each objective makes decision paralysis and bike-shedding in code review inevitable.


Why use await when you have processes? Await would feel very much out of place in the erlang world.


Erlang doesn't have promises. The main draw of the BEAM ecosystem is that it has a different concurrency system which is capable of many things that the JavaScript one is not.


The JS approach is worse than a do-notation approach because it is not extensible. Now we are stuck without cancellation token propagation (forever?)


I actually find kotlins syntax for this a bit more verbose and less confusing. But there are tradeoffs for both.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: