Monads should be a familiar concept for the seasoned C# programmer. LINQ's 'from in' syntax and the haskell monad 'do' syntax are almost the same!
Heck, the type signature of SelectMany and (>>=) are even the same!
(>>=) :: m a -> (a -> m b) -> m b
and public static IEnumerable<TResult> SelectMany<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, IEnumerable<TResult>> selector
)
m = IEnumerable
b = TResult
a = TSource
=> m<a> SelectMany<a,b>(this m<a> source, Func<a,m<b>> selector)
The type signatures are _EXACTLY_ the same. This isn't a coincidence. LINQ is actually a monad :)So I think taking this approach to explain the Monad voodoo to a C# programmer is the way to go. He actually uses them already :)