because the code operating in a context has to keep it somehow
you specify how the operations are going to be chained
>>= can pass state behind the scenes, but it can do much mode
that's the essence of "programmable semicolon"
I even wrote a paragraph about that I think.
> If this was in Maybe Monad, if any of the operations that obtain values failed, resulting in Nothing, the whole function would automatically result in Nothing. The context, being responsible for chaining operations, is able to “look inside” their returned values and change behaviour according to them. There are some laws that dictate what operations are possible, to keep the program’s behavior reasonable, but nevertheless it still offers a lot of possibilities.
and for completeness/utility >> is >>= that discards the return value to chain a computation that doesn't want the return value of the previous function.
----- at least that's from the practical perspective. Of course `>>=` has a more formal definition, the one that @Cat wrote.
but to understand all that, you need to really read into what do notation is, what Monad laws are, etc. etc. and it doesn't really help in understanding how the hell that applies to anything.
@DeadMG so, in short, you can define an interface that can be implemented from outside of the class, and then accept implementations of that interface?
@DeadMG you know, I dunno how much have you read about Haskell monads, but the coolest thing they have, imho, is not just the ability to create one. Pretty much every instance of Monad defines its own typeclass. So, for example, State is a Monad, but its module defines MonadState. If you fulfill that, your Monad can be used in place of State.
that's very powerful, because it means that you're writing code against monad interfaces, not against the particular instance.
but what you can do is not assume that one particular dynamic state obviously meets those invariants, even when you have absolutely no idea what those invariants are.
if you have a Wide function, then it has this method BuildCall() which constructs a run-time call to that function, and it takes a std::vector of arguments.
but it's pretty clear in advance that the arguments have to match the function's parameters.
@DeadMG I mean, the first thing I'd do is create the Empty concept and instantiate it for Vector and String and whatnot supplying those, so I don't have to think about them later.
like, I could have template<typename T> int f() { if (sizeof(T) > 5) return 1; }, pretty clear that some instantiations should be warned on but not others.