At least I saw it in Elixir in Action, use GenServer or something...
Elixir’s use: https://hexdocs.pm/elixir/main/alias-require-and-import.html...
Gleam’s use: https://tour.gleam.run/advanced-features/use/
In general, I find "use" a big deviation from Gleam's philosophy. Everything else in the language is well-defined and serves a specific purpose. "use", however, serves several goals, and thus is ambiguous (in the sense that it doesn't have one well-defined definition). [0, 1]
[0]: https://www.reddit.com/r/ProgrammingLanguages/comments/19ctw...
I find that `use` is quite effective when needed. This is the part referenced in her article where I find `use` particularly helpful. Something like:
fn outer() -> Result(success, failure) {
result.map(parse_id(), fn(id) {
... // More code that uses the id
})
}
Becomes: fn outer() -> Result(success, failure) {
use id <- result.map(parse_id())
... // More code that uses the id
}
In more concrete terms, I’m building an application with Gleam and Wisp that uses Wisp’s `require_form`. The type signature for `require_form` is: pub fn require_form(
request: Request(Connection),
next: fn(FormData) -> Response(Body),
) -> Response(Body)
But I get to use it like this: use form <- wisp.require_form(req)
I’m not sure if I have the appropriate nomenclature here, and I consider myself a beginner of writing strongly typed functional languages, but when I use `use`, I get to invoke the callback with the value on the left side of the arrow.As Erika so thoughtfully put it:
> The key is to use `use` when it allows you to highlight the happy path of your code … A use expression is syntax sugar, and it’s always possible to write Gleam code without it, though maybe not as clearly.
You can see more here [1] if you want, but note that there are a lot of structural changes in this codebase while I learn and figure out how to best use Gleam and Wisp :)
1. https://github.com/usepriceflow/app/blob/main/src/app/web/ad...
The thing is, though, browser-based APIs let you do all of that now, in a way that is usually a lot simpler to access. In these cases it's often a lot easier to just build a Progressive Web App for Android (Google let's you put PWAs directly in the Play Store), and wrap that with a thin native wrapper for iOS.
One of the big "aha" moments I had was a couple years ago when I was trying out Stripe's Identity product, which lets you take a selfie and a picture of your ID for identity verification purposes. It's pretty amazing how Stripe was able to do the full image analysis (i.e. edge detection when you take a picture of your ID) solely with browser APIs.
With the big exception of games, there are a vanishingly small number of apps that really require native functionality these days, given what you can do in the browser.
I wonder how Gleam compares to the type checking support being added to Elixir?
To me, Gleam feels like if Elm’s type system met Rust’s syntax. I really like it. But I also really liked Elixir too, I just can’t live without Gleam’s type system anymore.