From: jim Date: Fri, 20 Feb 2015 18:06:19 +0000 (-0500) Subject: need empty? for set questions X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=d4d2725db9c0d3367d8418971bdddf4ceaba73e1;hp=1e1c2aa31bd746a5de73a7563df469b75a2e8cb5 need empty? for set questions --- diff --git a/exercises/_assignment4.mdwn b/exercises/_assignment4.mdwn index 1ef8917b..441d773f 100644 --- a/exercises/_assignment4.mdwn +++ b/exercises/_assignment4.mdwn @@ -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]]. @@ -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 ...