A monad is a fancy word for a generic type of the form MyMonad<T>
(a generic type of arity 1).
A monad is special because it adds 'special powers' to the T
that it wraps.
These 'special powers' won't sound very special to an imperative programmer, so you have to squint to see them but bear with me.
IEnumerable<T>
is a monad that gives values of typeT
the special power of nondeterminism, or the ability to 'be' multiple values at once.Nullable<T>
is a monad that gives values of typeT
the special power of nullability, or the ability to be absent.Task<T>
is a monad that gives values of typeT
the special power of asynchronicity, or the ability to be used before they are computed.
The trick with monads comes when you want to play with the T
values, because they are inside another type. C# introduced language changes to make dealing with values inside these monads easier: