Remix.run Logo
eddlgtm 12 hours ago

Monads are just monoids in the category of endofunctors.

/s

Monads are, in my head, just a wrapper around a type. Or a box another type is inside. For example we can have an Int and we can put the Int in a box like Maybe<Int>.

Imagine Python code that gets a value from a function that is an Int or None, then another function that takes an Int and returns an Int or None, then another function that takes an Int and returns an Int or None. How hellish is that to handle? If not None, if not none, if not none, ad nauseam...

In Haskell I could use a Traverse function that takes a monad and passes the Int value to the next function or handles the None error, avoiding all the boilerplate.

Other Monads are like the State monad - a box that contains some variables I want to maintain over functions.

Or an IO monad to handle network calls / file calls.

It's probably not a perfect analogy, but I work with functional languages and it tends to hold up for my beginner/intermediate level.