X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=topics%2Fweek7_introducing_monads.mdwn;h=8b3428c30102ce66c37c2e05dcf7cef50a0f93fe;hb=0e24e1b63b8c5a7a1ffbe6ada981d0d24b6d6914;hp=0e9ab56f31b6f42592fe0dcd20801f7da6f9b892;hpb=5b304e0cbe18ba3bc9b372e3ca8faf3edaa4e8e5;p=lambda.git
diff --git a/topics/week7_introducing_monads.mdwn b/topics/week7_introducing_monads.mdwn
index 0e9ab56f..8b3428c3 100644
--- a/topics/week7_introducing_monads.mdwn
+++ b/topics/week7_introducing_monads.mdwn
@@ -1,5 +1,4 @@
-
The [[tradition in the functional programming
@@ -383,7 +382,7 @@ That can be helpful, but it only enables us to have _zero or one_ elements in th
| [] -> []
| x' :: xs' -> List.append (k x') (catmap f xs')
-Now we can have as many elements in the result for a given `α` as `k` cares to return. Another way to write `catmap k xs` is as `List.concat (map k xs)`. And this is just the definition of `mbind` or `>>=` for the List Monad. The definition of `mcomp` or `<=<`, that we gave above, differs only in that it's the way to compose two functions `j` and `k`, that you'd want to `catmap`, rather than the way to `catmap` one of those functions over a value that's already a list.
+Now we can have as many elements in the result for a given `α` as `k` cares to return. Another way to write `catmap k xs` is as (Haskell) `concat (map k cs)` or (OCaml) `List.flatten (List.map k xs)`. And this is just the definition of `mbind` or `>>=` for the List Monad. The definition of `mcomp` or `<=<`, that we gave above, differs only in that it's the way to compose two functions `j` and `k`, that you'd want to `catmap`, rather than the way to `catmap` one of those functions over a value that's already a list.
This example is a good intuitive basis for thinking about the notions of `mbind` and `mcomp` more generally. Thus `mbind` for the option/Maybe type takes an option value, applies `k` to its element (if there is one), and returns the resulting option value. `mbind` for a tree with `α`-labeled leaves would apply `k` to each of the leaves, and return a tree containing arbitrarily large subtrees in place of all its former leaves, depending on what `k` returned.
@@ -392,12 +391,15 @@ This example is a good intuitive basis for thinking about the notions of `mbind`
Some a >>=α option (\a -> Some 0) ==> Some 0
None >>=α option (\a -> Some 0) ==> None
-
- . _____
- / \ . / \
- . 3 >>=(α,unit) tree (\a -> / \ ) ==> _/_ .
- / \ a a / \ / \
-1 2 . . 3 3
+ Some a >>=α option (\a -> None ) ==> None
+
+ .
+ / \
+ . / \
+ / \ . . \
+ . 3 >>=(α,unit) tree (\a -> / \ ) ==> / \ .
+ / \ a a / \ / \
+1 2 . . 3 3
/ \ / \
1 1 2 2
@@ -436,6 +438,8 @@ As we mentioned above, the notions of Monads have their origin in Category Theor
[2](http://lambda1.jimpryor.net/advanced_topics/monads_in_category_theory/)
[3](http://en.wikibooks.org/wiki/Haskell/Category_theory)
[4](https://wiki.haskell.org/Category_theory), where you should follow the further links discussing Functors, Natural Transformations, and Monads.
+[5](http://www.stephendiehl.com/posts/monads.html)
+
Here are some papers that introduced Monads into functional programming: