I've tried reading (but not coding), and all I hear is sequence of operations, chaining, and similar. I know I'm missing something.
Basically I haven't seen or synthesized the tl;dr that makes me want to learn a language that has them.
I've tried reading (but not coding), and all I hear is sequence of operations, chaining, and similar. I know I'm missing something.
Basically I haven't seen or synthesized the tl;dr that makes me want to learn a language that has them.
As far as other uses: The best explanation that I've seen is that they let you hide the parts that you need to do, but that aren't the real thing your doing. Logging, for instance. You can add logging to something, and just string functions together as if there were no logging going on. (Of course, if you were doing non-pure-functional programming, you could just add logging statements wherever you wanted, and string your functions together just the same...)
You can check out this module:
http://hackage.haskell.org/package/base-4.8.1.0/docs/Control...
You can see all the varied sorts of things which are "instances of Monad", then scroll beyond and see all these different useful operations which behave sensibly for all those different instances (and from which you can build your own more complex operations which work for any Monad, and which also behave sensibly).
For instance in C#, there is a monad with bind=?? and return=no-op (similar in use to the Maybe monad in Haskell). There's another monad with bind=; and return=no-op (similar in use to the IO monad in Haskell). C# just doesn't explicitly recognize those as monads.
I think mode C# programmers would likely think of ';' and '??' as syntax, and who is thinking of 'no-op' as anything!?
But if you were in haskell this would not be syntax, but just functions on an instance of the Monad type class.
Haskell could easily add some sugar to make these constructs syntax as well, but it would just be sugar -- and that is where the power, and confusion I think arises when most programmers think about monads.
"All useful languages have monads ... nearly impossible to avoid."
So here's a post on Python (hopefully useful) and monads, it appears to be implementing a pattern, although I don't think I would have ever stumbled across it naturally.
http://www.valuedlessons.com/2008/01/monads-in-python-with-n...
And here's a library implementing monads and other stuff:
https://pypi.python.org/pypi/PyMonad/
It still looks like I'm going to have to try using them before I can figure out if it's worth trying to use them.