Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created November 19, 2013 21:48
Show Gist options
  • Save bananu7/6a21d498af8471ef23fc to your computer and use it in GitHub Desktop.
Save bananu7/6a21d498af8471ef23fc to your computer and use it in GitHub Desktop.

#Monads

  1. Formal definition
    • M a
    • (M a) -> (a -> M b) -> (M b)
  2. "Common" definition
    • A wrapped value - a value in a box This description seems conceptually easy, but
    • A hidden computation
  3. 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!
  4. 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)
  5. Examples of extended function contracts
    • Reader
    • Writer
    • State
  6. Relations to Functors and Applicative Functors
  7. Questions?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment