add suggestion about leaf? function
[lambda.git] / exercises / assignment4.mdwn
index 8bbeffe..6f992b3 100644 (file)
@@ -62,6 +62,7 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
         let empty = \f n. n in
         let cons = \x xs. \f n. f x xs in
         let empty? = \xs. xs (\y ys. false) true in
+        let head = \xs. xs (\y ys. y) err in
         let tail = \xs. xs (\y ys. ys) empty in
         let append = Y (\append. \xs zs. xs (\y ys. (cons y (append ys zs))) zs) in
         let take_while = Y (\take_while. \p xs. xs (\y ys. (p y) (cons y (take_while p ys)) empty) empty) in
@@ -102,7 +103,7 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
 
     Some limitations of this scheme: there is no easy way to label an inner, branching node (for example with a syntactic category like VP), and there is no way to represent a tree in which a mother node has a single daughter.
 
-    When processing a tree, you can test for whether the tree is a leaf node (that is, contains only a single number), by testing whether the length of the list is 1. This will be your base case for your recursive definitions that work on these trees.
+    When processing a tree, you can test for whether the tree is a leaf node (that is, contains only a single number), by testing whether the length of the list is 1. This will be your base case for your recursive definitions that work on these trees. (You'll probably want to write a function `leaf?` that compartmentalizes this check.)
 
     Your assignment is to write a Lambda Calculus function that expects a tree, encoded in the way just described, as an argument, and returns the sum of its leaves as a result. So for all of the trees listed above, it should return `1 + 2 + 3`, namely `6`. You can use any Lambda Calculus implementation of lists you like.