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

@aescling i actually think that you saying that you can think of more than one monad on List helped with this in that

i felt skeptical in the sense of "this makes sense for this case but i feel that it would fall apart for some other use case of List. i don't believe that i could describe everything i've ever done with List this way"

but i guess i don't have to, right?

Follow

@monorail yeah, not all use cases fur list make sense as a monad. this is actually why it's impurrtant imo to sepurrate the data type from a monad built around it

@monorail you can build an interface around a list such that everything using that interface is purrfurming non-deterministic computations, BUT, if you do arbitrary shit to a list directly, you don’t have the guarantee that that abstraction will make any sense

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.