Monads are hard to understand because you are terribly obsessed with objectifying them.

👇 👇 👇
Monads are not objects, they are not things. Stop trying to point a finger at them.
Monads are a relationship between things.
Monads are an opportunity for future things to depend on outcomes from past things.
Monads say there's a moment when past things have already happened, and we know of their consequences, but the future things, the plan, hasn't been decided yet.
The things you should worry about are Functorial Values. You can point a finger at those.
A Functorial Value produces an output. For example, a function 'a -> b' is a Functorial Value producing that 'b'.

In this case, the Functor is the 'a ->' part, also written '(->) a'.
Sometimes, you can also think of Functorial Values as containing a thing. Such as 'Maybe b', which perhaps contains a 'b', or '[b]', which may contain zero or more of them.

In these cases, the 'Maybe' and '[]' type constructors are the Functors.
What if, given one of those 'b's, one of the outputs from these Functorial Values, you could create a new Functorial Value, on the same Functor, producing a 'c' instead?

b -> (a -> c)

b -> Maybe c

b -> [c]
If you could do that, if you have the opportunity to decide what a new Functorial Value will be depending on what another Functorial Value produced before, then stop searching, you have found what you were looking for.
In Haskell, the type of (>>=) represents this idea, this opportunity.
(>>=) :: f b -> (b -> f c) -> f c

Given a Functorial Value producing a 'b', and a way to decide, based on that 'b', how to construct a Functorial Value producing a 'c', then construct that Functorial Value producing a 'c'.
'f b' could be 'a -> b', 'Maybe b', '[b]' or any other Functorial Value producing a 'b'.

The 'f' is a Functor, like '(->) a', or 'Maybe' or '[]'.

The 'b's and 'c's could be any type. 'Int', 'Bool', or maybe even another Functorial Value.
Obviously, the implementation of (>>=) will be different for each of our Functors. But the way we use it, and what it means, is always the same.
Future Functorial Values depending on outputs from past Functorial Values. That's it.
You can follow @k0001.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: