←back to thread

289 points kristoff_it | 9 comments | | HN request time: 0.001s | source | bottom
Show context
raluk ◴[] No.44609651[source]
One thing that most languages are lacking is expressing lazy return values. -> await f1() + await f2() and to express this concurently requres manually handing of futures.
replies(3): >>44609880 #>>44610056 #>>44610348 #
1. sedatk ◴[] No.44609880[source]
Which languages do have such a thing?
replies(2): >>44610179 #>>44610709 #
2. Twey ◴[] No.44610179[source]
I suppose Haskell does, as `(+) <$> f1 <*> f2`.
replies(1): >>44612756 #
3. steveklabnik ◴[] No.44610709[source]
Rust does this, if you don’t call await on them. You can then await on the join of both.
replies(1): >>44610738 #
4. sedatk ◴[] No.44610738[source]
Is the "join" syntax part of the language?
replies(2): >>44611332 #>>44613040 #
5. tcfhgj ◴[] No.44611332{3}[source]
no

https://doc.rust-lang.org/std/future/macro.join.html

replies(1): >>44612037 #
6. sedatk ◴[] No.44612037{4}[source]
Then it doesn’t apply in this case.
replies(1): >>44615353 #
7. raluk ◴[] No.44612756[source]
In there is also ApplicativeDo that works nicely with this.

    do 
      x <- f1
      y <- f2
      return $ x + y
this is evaluated as applicative in same way.
8. deathanatos ◴[] No.44613040{3}[source]
Why is having it be syntax necessary or beneficial?

One might say "Rust's existing feature set makes this possible already, why dedicate syntax where none is needed?"

(…and I think that's a reasonably pragmatic stance, too. Joins/selects are somewhat infrequent, the impediments that writing out a join puts on the program relatively light… what problem would be solved?

vs. `?`, which sugars a common thing that non-dedicated syntax can represent (a try! macro is sufficient to replace ?) but for which the burden on the coder is much higher, in terms of code readability & writability.)

9. tcfhgj ◴[] No.44615353{5}[source]
why?