projects
/
lambda.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
4398d51
)
update some functions
author
jim
<jim@web>
Fri, 20 Feb 2015 17:48:40 +0000
(12:48 -0500)
committer
Linux User
<ikiwiki@localhost.members.linode.com>
Fri, 20 Feb 2015 17:48:40 +0000
(12:48 -0500)
exercises/_assignment4.mdwn
patch
|
blob
|
history
diff --git
a/exercises/_assignment4.mdwn
b/exercises/_assignment4.mdwn
index
4dfd5db
..
3eec4e6
100644
(file)
--- 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 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 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
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
-->
; all functions from the previous question, plus
- let num_equal? = ??? in
+ ; `num_cmp x y lt eq gt` returns lt when x<y, eq when x==y, gt when x>y
+ 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
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