@reese

I was introduced to monads thru C#.. C#'s iterator interface IEnumerable<T> is a monad. Maybe<T> is like an iterator that only iterates once, so instead of zero or more values, it can have zero or one value.

Just like how one might write

mysequence.map(x => x+1)

to add one to every number in a sequence (without having to know how many there are or having to load all of them in RAM before starting)

One can also write

maybething.map(x => x+1)

to add one to a number without having to know if it exists or not.

The "without having to know if it exists or not" part is the special magic... Not only does it help prevent null reference exceptions, it also allows languages like C# to build in declarative (SQL-like) features directly into the language. That's what LINQ (Language-Integrated Query) in C#.

Declarative meaning we don't tell it **how** to process the data, we just tell it what we want and it figures out the most efficient way to get there.

Follow

@reese This is probably at least partially wrong information but I think it speaks a little bit to what monads are good for / why anyone would give a shit about them

Sign in to participate in the conversation
Pixietown

Small server part of the pixie.town infrastructure. Registration is closed.