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 this concept at my developments with c#.
Thanks for help.
Monads are abstract, and they have many useful concrete instances. Monads provide a way to structure a program. They can be used (along with abstract data types) to allow actions (e.g. mutable variables) to be implemented safely.
In C# terms, a Monad is a generic class with two operations: constructor and bind. class Monad<T> { Monad(T instance); Monad<U> Bind(Func<T, Monad<U>> f); } Constructor is used to put an object into container, Bind is used to replace one contained object with another contained object.
Monads are simply a way to wrapping things and provide methods to do operations on the wrapped stuff without unwrapping it. For example, you can create a type to wrap another one, in Haskell: data Wrapped a = Wrap a. To wrap stuff we define return :: a -> Wrapped a return x = Wrap x.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With