4 ms·
Not 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. B
by goto11 7y ago
Not 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.