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.
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.
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
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.
> 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.
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.