-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Gleam-like use
expressions?
#6612
Comments
Yep, we don't have a way to bind the JavaScript's Disposable/AsyncDisposable and to use |
I don't think it's really the same thing, it can be one case of it though... It's more like OCaml's |
I'm very fresh to compiler implementation, but I'd perhaps give it a try when I'm ready |
AFAIK monadic let binding is one of the features we gave up in choosing a representation closer to JS. Support for some generalized syntax that's not common in JS is still controversial, but support for those widely present in the JS standard is clearly something that is needed. |
I don't think it's up to me to dictate language design, it's just what I feel is easy enough to grasp, and can allow lots of possibilities. It's just a sugar for callback passing. let x = {
use a <- f;
f2(a);
} Would be de-sugared into let x = f(a => f2(a)); So when async/await solve one case of callback-hell, very valuable, ngl. But I feel like use could cover async/await if needed, and do a lot more. Even more than monadic bind, actually. So I'm not going to push for it, that is my opinion, so if it doesn't fit the vision, please disregard this suggestion, we can close it |
As I can see, these two code examples are not the same. |
That is indeed a correct observation, the former is with suggested syntactic sugar, the latter is without. Perhaps I messed up the semicolon? Apologies, I was typing through my phone. Since ReScript does not provide that syntax yet, I'll post a gleam snippet here for demonstration. import gleam/io
import gleam/bool
pub fn main() {
let x = {
use a <- f
f2(a)
}
let y = f(fn(a) {f2(a)})
io.print(bool.to_string(x == y))
}
fn f2(x) {
x + 1
}
fn f(cb) {
cb(5)
} It can be pasted in here. The idea is to perhaps add this syntactic sugar into ReScript. For deeper dive I really recommend reading the link I initially posted, it can work as async/await, as an Option.flatMap, as Option.map too, it just flattens the callback hell of any kind for you |
I don't think this feature request is related to Disposables / |
Thank you for filing! Check list:
I found it so neat and flexible, I am surprised no one else has done this before.
Gleam Use Expressions
I think gleam has very similar semantic to ReScript and this is a very useful sugar
The text was updated successfully, but these errors were encountered: