Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there some usage of monads at .net environment?

Tags:

c#

.net

monads

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.

like image 548
Night Walker Avatar asked Dec 20 '10 08:12

Night Walker


People also ask

What are monads useful for?

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.

What is monad in C#?

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.

What are monads explain with example?

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.


2 Answers

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.

like image 174
Jon Skeet Avatar answered Sep 25 '22 00:09

Jon Skeet


  • The Async Monad in F#'s asynchronous workflows (the async in C# isn't monadic)
  • The List comprehension Monad, in .NET's LinQ
like image 28
Aggelos Biboudis Avatar answered Sep 21 '22 00:09

Aggelos Biboudis