watching a video about what a monad is because i've never understood them despite trying. they set up this simple toy example to motivate everything and then went "so, where do monads come in? surprise: we just wrote one". screaming and crying and shitting my pants. i was deceived.

(posted it in a reply but: i actually want this link in the OP as well. youtu.be/C2w45qRc3aU)

monads spoilers 

okay i've read explanations of monads that explained what they're for and didn't get it. and i've read explanations of monads that explained "a monad is just when you have these two functions" and didn't get it. but this video has both "here's what they're for. to accomplish that you just need these two functions" and i think i get it?? youtu.be/C2w45qRc3aU

monads spoilers 

like "Option is a monad" didn't make sense to me but "Option is a monad, because we take a value and put it in its own little 'Option' ecosystem and pass any transformations we want to do into it, and the case of 'no value' is handled by the inner workings of that ecosystem without any extra work" kind of does

okay i'd like to check my understanding. can someone who actually does understand monads confirm this for me

when you take a value of type T and put it into an Option<T>, you're putting that value into a context that abstracts away some work. you can still do things to the value, but you're doing it via Option, which is what allows it to do that abstraction

and that's what makes Option a monad? that's what a monad is?

"at the start of the video, we wrote a monad that accumulates logs as you perform operations on a value" got it

"Option is a monad. we went through exactly how and why, and used it as a more in depth example of why this is a useful pattern" got it

"Future/Promise is a monad, but we won't go into depth about that in this video" i think i mostly get this. not to the same degree but i can see how we're putting values into a context where it's okay that the value isn't ready yet, the same way that Option puts values into a context where it's okay that the value doesn't exist

"List is a monad, let's go over that" this one hit me like a left hook. this is going to be good

i tried to understand the explanation of List as a monad and found myself skeptical. then the video said "If you're feeling skeptical about this explanation, that's okay". so i guess that's okay

@monorail if you ever look into coding a monadic parser with nondeterministic output i think the idea of list-monad-as-parallel-universes might click into place fur you

Follow

@monorail a n y w a y look into monadic parsing sometime it's very cool

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.