8 ms·
In C#, you can't use the await keyword in a non async method, so I find the argument short sighted.
by smoothdeveloper 1y ago
In C#, you can't use the await keyword in a non async method, so I find the argument short sighted.
- shortrounddev2 1y agoI don't see how that changes things. You'd have to async it all the way to the top but the syntax is still cleaner than F#. If you're using an Asp.Net controller you just declare the handler as async Task<IActionResult> and it's fine. Even program main methods can be async these days
- malakai521 1y agoThe syntax is exactly the same. You have `var x = await` in C# and `let! x =` in F# The controller handler is also the same. It will be marked with `async` keyword in C# and `task` CE in F#
- shortrounddev2 1y agoIt's absolutely not exactly the same; let! is only available within a computation block. If you want to return some value from the computation block and return to Functional land without having to pause the thread you need to use a continuation, which C# has built in syntactic sugar for in async/await and F# does not.
- sparkie 1y ago`await` can only be used in an `async` function. How is that so different from `let!` only being available in a computation expression?
- shortrounddev2 1y agobecause an async function doesn't require you to change syntaxes to get them to work
- Smaug123 1y agoIt's actually sort of the other way round. C# has hardcoded syntax for async/await. F#'s syntax for async/await is a fully-general user-accessible mechanism.
- sparkie 1y agoThey're not so different in that regard. C# `await` can be adapted by making an awaitable and awaiter type[1], which isn't to dissimilar to how a computation expression in F# needs to implement methods `Bind`, `Return`, `Yield`, etc. In both languages these patterns make up for the absence of typeclasses to express things like a functor, applicative, monad, comonad, etc. [1]https://ecma-international.org/wp-content/uploads/ECMA-334_7th_edition_december_2023.pdf#%5B%7B%22num%22%3A744%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C55%2C585%2C0%5D https://ecma-international.org/wp-content/uploads/ECMA-334_7...
- xigoi 1y agoA computation block is the equivatent of an async function;
- jayd16 1y agoIf your code base is already using async await it's really not an issue.
- int_19h 1y agoThe point is that it's not actually different from C#, especially once you consider that F# also has task{} blocks that give you a .NET Task directly.