4 ms·
Isn't the point of LINQ to get monads into the language so that it can be used by a lot of different things (seemingly having no relations to data processing),
by kccqzy 7y ago
Isn't the point of LINQ to get monads into the language so that it can be used by a lot of different things (seemingly having no relations to data processing), rather than just data processing tasks?
- mythz 7y agoI've no idea what you mean? LINQ is a "Language-Integrated Query" for the C# and VB.NET languages which built upon a number of features in .NET Framework v3.5 to make possible. It shipped with a "LINQ to Objects", "LINQ to SQL" and a "LINQ to XML" provider. Of the features that differentiates it from querying functionality in other languages is its Expression Trees support that I've highlighted in my last paragraph which is essential for being able to implement alternative LINQ providers.
- goto11 7y agoNot really. You can have monads without Linq, but there is a particular use of the 'from' syntax which can be used as a cleaner syntax for monadic operations. But this seem more like a hack than an intended use case. It is rumored that Linq was initially implemented using monads, but that approach was abandoned due to performance reasons.
- contravariant 7y agoThat rumour seems like it's false, because not only is "implemented using monads" a rather vague qualification, Linq has currently been implemented by requiring objects to implement the SelectMany function, which has signature: MyObject<B> SelectMany(MyObject<A>, Func<A, MyObject<B>>) or perhaps more familiar to the Haskell folks: SelectMany :: M a -> (a -> M b) -> M b i.e. exactly the 'bind' operator for Monads. I think you also need to implement a 'Select :: M a -> M b' operator, rather than a 'return :: a -> M a' operator, which would be closer to a true Monad, but the 'bind' operator is the one that really matters anyway.
- goto11 7y agoThe rumor was that the standard extension methods on IEnumerable<T> like Join, Select, Where, Group were all implemented on top of SelectMany. I call it a rumor because I cannot remember where I read it, so it is quite possible I have misunderstood it.
- elfexec 7y agoThe point of LINQ was to get a native data querying into .Net framework - primarily targetting database servers ( SQL Server ), but also XML, enumerables, etc. The query operators and the syntactic sugar tries to mimic SQL for I suppose familiarity and ease of use. Overall, it's an elegant way of processing data within .Net.
- brewmarche 7y agoI'm not sure whether it's the point of it, but since the LINQ syntax is essentially just do-notation (extended by things like join, group and order) it certainly allows for usages in other monadic contexts, for example with parser combinators. Here is an example: https://github.com/sprache/Sprache#usage https://github.com/sprache/Sprache#usage