"inner" expression
[lambda.git] / topics / week3_lists.mdwn
index 00f1ffd..14663cd 100644 (file)
@@ -80,13 +80,15 @@ To translate that, first let's handle the iteration over the final list, that `x
 
 This looks like what we had before, except that now we have this free variable `y` in our lambda expression. Perhaps we can bind that variable inside a *larger* lambda expression, and then map (and filter) *that* larger lambda expression over the list that `y` is drawn from:
 
-    map (lambda y. map (lambda x. 10*x + y) [1, 2, 3]) $ filter (lambda y. y < 6) [4, 5, 6]
+    let
+      f match lambda y. map (lambda x. 10*x + y) [1, 2, 3]
+    in map f $ filter (lambda y. y < 6) [4, 5, 6]
 
 This gives us nearly what we want. It evaluates to:
 
     [[14, 24, 34], [15, 25, 35]]
 
-Why? Because the `filter` expression at the end is restricting the domain that `y` ranges over to `[4, 5]`. Over this domain we are selecting a value to bind `y` to, and then evaluating the inner `map` expression with `y` so bound. With `y` bound to `4`, we get the result `[14, 24, 34]`. With `y` bound to `5`, we get the result `[15, 25, 35]`. These two results, in order, are the elements that make up the sequence which is the result of the outermost `map` expression.
+Why? Because the `filter` expression at the end is restricting the domain that `y` ranges over to `[4, 5]`. Over this domain we are selecting a value to bind `y` to, and then evaluating the `map` expression inside `f` with `y` so bound. With `y` bound to `4`, we get the result `[14, 24, 34]`. With `y` bound to `5`, we get the result `[15, 25, 35]`. These two results, in order, are the elements that make up the sequence which is the result of the outermost `map` expression.
 
 One final twist is that our original list comprehension gives us a "flatter" result. In both Kapulet (and Haskell, modulo a few syntax adjustments), the list comprehension: