I've been hanging out in a #haskell IRC room a couple of days ago and someone mentioned that C# has syntax for doing monadic comprehension. What does this mean?
If I understand correctly, monadic comprehension is just a way of sequencing bind
operations, which kind of sounds like a do
notation? Is that correct?
The problem is that I don't see this in C#. As far as I know IEnumerable<T>
is a monad where SelectMany
is its bind
function, as its signature is A -> IEnumerable<B>
. With a little stretch of imagination, we can do
from x in xs
from y in ys
which translates into (I'm not 100% sure here)
xs.SelectMany(x => ys.Select(y => y), (x, y) => ...)
But even if this is true and we think of LINQ as a monad comprehension syntax, it still only applies to IEnumerable<T>
. We do have other monads in C# like Task<T>
, but how can we use LINQ on those?
It is possible that many of the assumptions in this question are completele wrong, as I'm still trying to grasp some of the monad magic stuff. Please correct me if I'm wrong :)