From: jim Date: Fri, 20 Feb 2015 17:48:40 +0000 (-0500) Subject: update some functions X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=71f5a9d7f646424ae3c8e543f889f952ed6ea9d3;hp=4398d51300777f367c01ef6b88a664b8dfe733b2;ds=inline update some functions --- diff --git a/exercises/_assignment4.mdwn b/exercises/_assignment4.mdwn index 4dfd5dbf..3eec4e6a 100644 --- a/exercises/_assignment4.mdwn +++ b/exercises/_assignment4.mdwn @@ -27,9 +27,13 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~> let true = \y n. y in let false = \y n. n in - let zero? = \n. n (\p. false) true in - let pred = \n f z. n (\u v. v (u f)) (K z) I in + let pair = \a b. \v. v a b in + let fst = \a b. a in ; aka true + let snd = \a b. b in ; aka false + let zero = \s z. z in let succ = \n s z. s (n s z) in + let zero? = \n. n (\p. false) true in + let pred = \n. n (\p. p (\a b. pair (succ a) a)) (pair zero zero) snd in let add = \l r. r succ l in let mult = \l r. r (add l) 0 in let Y = \h. (\u. h (u u)) (\u. h (u u)) in @@ -46,7 +50,15 @@ For instance, `fact 0 ~~> 1`, `fact 1 ~~> 1`, `fact 2 ~~> 2`, `fact 3 ~~> --> ; all functions from the previous question, plus - let num_equal? = ??? in + ; `num_cmp x y lt eq gt` returns lt when xy + let num_cmp = (\base build consume. \l r. r consume (l build base) fst) + ; where base is + (pair (\a b c. b) (K (\a b c. a))) + ; and build is + (\p. pair (\a b c. c) p) + ; and consume is + (\p. p fst p (p snd) (p snd)) in + let num_equal? = \x y. num_cmp x y false true false in 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