X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=topics%2Fweek3_lists.mdwn;h=08b35162f470f8e61293534faa7c2633bbb1848b;hp=14663cda323d858fbbf762ce593089054b32b568;hb=63156a22b401c0fdbe7a6b98ac0e402977ec8a5b;hpb=3f14ad8bc8bc4e48423e1c2b30b32dd5bd929d2a diff --git a/topics/week3_lists.mdwn b/topics/week3_lists.mdwn index 14663cda..08b35162 100644 --- a/topics/week3_lists.mdwn +++ b/topics/week3_lists.mdwn @@ -1,5 +1,6 @@ # More on Lists # + ## Comprehensions ## We know you are already familiar with the following kind of notation for designating sets: @@ -48,7 +49,7 @@ Haskell also has an extension that permits you to iterate over multiple lists *i [ 10*x + y | y <- [4, 5, 6] | x <- [1, 2, 3] ] -will evaluate to `[14, 25, 36]`. If the lists are of unequal length, Haskell stops when it exhausts the first. These behaviors are similar to the `map2` function you defined in the week 1 homework. That also took an argument from each of several sequences in parallel. (The corresponding functions in Haskell are called `zip` and `zipWith`.) +will evaluate to `[14, 25, 36]`. If the lists are of unequal length, Haskell stops when it exhausts the shortest. These behaviors are similar to the `map2` function you defined in the week 1 homework. That also took an argument from each of several sequences in parallel. (The corresponding functions in Haskell are called `zip` and `zipWith`.) OCaml [permits lists comprehensions as an extension](http://stackoverflow.com/questions/27652428/list-comprehension-in-ocaml), and [so too does Scheme](http://srfi.schemers.org/srfi-42/srfi-42.html), but these are a bit harder to use. @@ -119,6 +120,8 @@ not to: To get the latter, you'd need to apply `join` twice. + + ## Tails ## For the Lambda Calculus, we've proposed to encode lists in terms of higher-order functions that perform right-folds on (what we intuitively regard as) the real list. Thus, the list we'd write in Kapulet or Haskell as: @@ -151,3 +154,5 @@ Try it out in the lambda evaluator. After the code above, you can write: and the result will be `\f z. f b (f c z)`, our encoding of `[b, c]`. + +