this post was submitted on 11 Oct 2025
289 points (96.2% liked)
Programmer Humor
27796 readers
1220 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Monad is (a classes of type of) a collapsible container. Collapsible, like how you can flatten a nested list, or Option<Option> can be flattened to Option.
A common pattern with monads is the flatMap function, where you apply function A -> List to (each element of) List to obtain List. This happen to represent erroneous call chaining with Option or Result types.
This is actually a good alternative explanation, as long as you clarify it a bit.
What is meant by "container" type is that it's possible to
unit/pure)map/fmap), without "taking any values out"Take for example a list.
unitis simple, as I've described in my comment:Map is also fairly straight-forward, just applying a given function to every element of the list:
Then your final operation ("flattening" the container) is traditionally called
join. It concatenates a list of lists into a single flat list:(you might notice that it is extremely similar to both
mapandbind)This allows us to define
bindfrom my other comment (which you callflatMap) in terms ofjoinandmap:Or, if you already have a
bind(andunit) defined, you can definejoinandmapas follows:Showing that a type defining
unitandbindis equivalent to a type definingunit,joinandmap- they are both equivalent definitions of a monad, you can derive one from another and vice versa.Historically, the
unit+binddefinition is more popular and aligns with what most functional languages do, so I went with it for my explanation. But yours is probably a bit easier to understand for an FP outsider.