need empty? for set questions
authorjim <jim@web>
Fri, 20 Feb 2015 18:06:19 +0000 (13:06 -0500)
committerLinux User <ikiwiki@localhost.members.linode.com>
Fri, 20 Feb 2015 18:06:19 +0000 (13:06 -0500)
exercises/_assignment4.mdwn

index 1ef8917..441d773 100644 (file)
@@ -48,7 +48,6 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
 
 6.  For this question, we want to implement **sets** of numbers in terms of lists of numbers, where we make sure as we construct those lists that they never contain a single number more than once. (It would be even more efficient if we made sure that the lists were always sorted, but we won't try to implement that refinement here.) To enforce the idea of modularity, let's suppose you don't know the details of how the lists are implemented. You just are given the functions defined below for them (but pretend you don't see the actual definitions). These define lists in terms of [[one of the new encodings discussed last week|/topics/week3_lists#v5-lists]].
     <!--
-    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
     -->
@@ -66,6 +65,7 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~>
         let neg = \b y n. b n y in
         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 take_while = Y (\take_while. \p xs. xs (\y ys. (p y) (cons y (take_while p ys)) empty) empty) in
         let drop_while = Y (\drop_while. \p xs. xs (\y ys. (p y) (drop_while p ys) xs) empty) in
         ...