#Monads
- Formal definition
M a
(M a) -> (a -> M b) -> (M b)
- "Common" definition
- A wrapped value - a value in a box This description seems conceptually easy, but
- A hidden computation
- The most basic Monad -
Maybe
- A box that can hold a value and can be empty
- Box analogy is very limited
- A computation that might produce a value - much better!
- A bit of reasoning about functional purity before we proceed
- The explicit function contract Function given the same input must always give the same output
- We are "cheating" - HOFs are a way to "break" the purity Because a HOF seeing a (bound) function sees it for the first time, and thus is in practice unlimited as to what it might output).
- Monads are a convenient way to encapsulate computations while still keeping functional purity. They essentially limit what we can do with the computations, and that's more explicit -> better (why is beyond the scope of this presentation, quick remark about The Pit of Success)
- Examples of extended function contracts
- Reader
- Writer
- State
- Relations to Functors and Applicative Functors
- Questions?