3 ms·
Thanks for this article! > the connection between await as an operator and sampleas an operator is deeper than you might think. Can anyone explain this to me
by inglor 7y ago
Thanks for this article!
> the connection between await as an operator and sampleas an operator is deeper than you might think.
Can anyone explain this to me?
Await plays the part of "specialized haskell like `do`" with tasks being a continuation monad (and co-monad). `sample` does the same playing the same role of "do" - where is the "deeper connection"?
- Faark 7y ago> Can anyone explain this to me? Awaits / yields produce state machines. See [0] for an example of how that works behind the scene (or just decompile your stuff with ILSpy/dotPeek), but basically the code between yields / awaits is split into separate blocks in a new object, all variables used across multiple blocks are stored in that object along side of some state indicating where to continue on next call. Lets pretend we only use immutable data/vars for now. We could just reset the state machines position to some earlier state and re-run it. Only with our await-like sample operator returning a different value this time. Add another operator and this would make it very easy to implement backtracking while re-using a lot of existing behind the scene infrastructure. But personally I'm not sure the result is that much easier readable than a few nested for loops. It might be, for some complicated code spread across a larger code base. But adding a new language operator is a quite high price to pay... [0] https://mycodingplace.wordpress.com/2017/07/19/csharp-behind-the-scenes-yield/ https://mycodingplace.wordpress.com/2017/07/19/csharp-behind...