Is there some usage of monads at .net environment?
I have learned few days ago how about Haskell monads, is there some usage of monads concept at .net environment ? And is there ways to use t开发者_StackOverflow中文版his concept at my developments with c#.
Thanks for help.
Well, LINQ itself is based on a monad, via SelectMany
. See Wes Dyer's blog post on the topic for more explanation.
They're not commonly used outside that though, and most LINQ users won't think of themselves as using monads.
- The Async Monad in F#'s asynchronous workflows (the async in C# isn't monadic)
- The List comprehension Monad, in .NET's LinQ
Haskell is a functional programming language. There is nothing special about this, but its design makes it easy to learn and comprehend and very effective and efficient in practice. A very special feature of Haskell is the concept of generalization. That means, instead of implementing an idea directly, you rather try to find a more general idea, which implies your idea as a special case. This has the advantage that if you find other special cases in the future, you don't need to implement them, or at least not fully from scratch.
But it does not mean that you can not do all thing in c#, There are many component in .net which is internally use the same concept which you are getting in Monads. even most developer used it but they are not aware of the name "Monads".
If you want to use same syntax in c# then you can not do it.
If you read this article of Monads then you will easly know that all concept of Monads are is in c#.
In addition to Jon's answer, check out this very interesting as well as entertaining Expert to Expert video about LINQ's mathematical dual, the reactive framework:
Channel 9 - Expert to Expert
In C# 6.0 there is a monadic Null-conditional operator ?.
It helps to simplify null checking when you need to retrieve value from nested object property where anything along the way can be null. You can read more here in section Null-conditional operators.
精彩评论