4 ms·
> An async function and a normal function are semantically the same But they are not, AsyncIO and BlockingIO are different side effects, thus you have differen
by ernst_klim 6y ago
> An async function and a normal function are semantically the same
But they are not, AsyncIO and BlockingIO are different side effects, thus you have different types of computation, that's exactly what I'm talking about. In languages with monads or algebraic effects these would have different types.
You don't say that Lists and Arrays are semantically the same, despite being similar sequential collections, they still have separate types for a reason. Though it's good to be able to abstract over them.
And in languages with monads we can parametrize over various effect types by using tagless final approach, which allows us to write computations which could be interpreted in contexts of various effects (in this case, Async and Sync), just as we parametrize containers with types of content (in [1] there is an example of how we can parametrize computation over various async implementations), but still these are different effects.
[1] https://kubuszok.com/2019/io-monad-which-why-and-how/#typed-tagless-final-interpreter https://kubuszok.com/2019/io-monad-which-why-and-how/#typed-...
- gpderetta 6y agoI don't think considering the blocking strategy an effect is very useful. Even in async context in complex enough applications functions can call other functions including your own, so async is not enough to guarantee reentrancy. I do agree that parametrizing over the blocking strategy is a great idea, but languages that simply provide an async syntactic marker don't necessarily allow that, and if your language is powerful enough you do not need the annotation in the first place.