3 ms·
If you had to chose right now and abandon the other, would you pick LINQ or discriminated unions?
by CrimsonCape 3y ago
If you had to chose right now and abandon the other, would you pick LINQ or discriminated unions?
- Turskarama 3y agoNot OP but I would choose discriminated unions. Why? because Linq is basically just syntactic sugar for regular IEnumerable methods, while discriminated unions have no equivalent at all. Even if you wanted to claim that those IEnumerable methods ARE linq, then it would still be possible to implement them with a library while discriminated unions have to be a compiler feature.
- pharmakom 3y agoYep, Linq could be replaced by the more general Computation Expressions in F#
- WorldMaker 3y agoF# has a query { } expression for LINQ already.
- pharmakom 3y agoI'm talking about improving C# by replacing LINQ with the more general Computation Expressions.
- WorldMaker 3y agoAh. The C# compiler "duck types" LINQ so you can already (ab)use LINQ for general computation in C#. You can use nearly any Monad you want with LINQ syntax. It isn't always a strong fit for some types of Monads, but it is more capable than it seems. You might get some funny looks if you do, though. (Similar with async/await: it is "duck typed" at compile time so you can write other Monads for that, if they make more sense in that form of transformer than LINQ. Or support both LINQ and async/await together.) There's definitely some more interesting power in F#'s Computation Expressions that can't easily be done even with (ab)using the tools that already exist like that, but it is still interesting what can be done with the existing tools.
- pharmakom 3y agoI don't think that LINQ has support for appicatives or custom operators. Although yes, it can be abused in impressive ways :)