From e90eacbc70fb086d60ed0523c184f27160919792 Mon Sep 17 00:00:00 2001 From: jim Date: Tue, 24 Feb 2015 15:42:21 -0500 Subject: [PATCH] tweak explanation of Bunder/Urbanek pred --- exercises/assignment3_answers.mdwn | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/exercises/assignment3_answers.mdwn b/exercises/assignment3_answers.mdwn index ae35731b..08375b69 100644 --- a/exercises/assignment3_answers.mdwn +++ b/exercises/assignment3_answers.mdwn @@ -119,17 +119,18 @@ > Here is another solution, due to Martin Bunder and F. Urbanek: - > let pred = \n. \s z. n (\u v. v (u s)) (K z) I in + > let box = \a. \v. v a in + > let pred = \n. \s z. n (\b. box (b s)) (K z) I in > ... - > That can be hard to wrap your head around. If you trace it through, you'll see that: + > That can be hard to wrap your head around. If you trace this expression through, you'll see that: - > * when `n == 0`, it reduces to `\s z. (\v. z) I`, or `\s z. z` - > * when `n == 1`, it reduces to `\s z. (\v. v z) I`, or `\s z. z` - > * when `n == 2`, it reduces to `\s z. (\v. v (s z)) I`, or `\s z. s z` - > * when `n == 3`, it reduces to `\s z. (\v. v (s (s z))) I`, or `\s z. s (s z)` + > * when `n == 0`, it reduces to `\s z. (K z) I`, or `\s z. z` + > * when `n == 1`, it reduces to `\s z. (box z) I`, or `\s z. z` + > * when `n == 2`, it reduces to `\s z. (box (s z)) I`, or `\s z. s z` + > * when `n == 3`, it reduces to `\s z. (box (s (s z))) I`, or `\s z. s (s z)` - > The technique used here is akin to that used in [[the hint for last week's `reverse`|assignment2_answers#cps-reverse]]. + > `box a` is `\v. v a`; this stands to `pair a b` as one stands to two. Since boxes (like pairs) are really just functions, the technique used in this definition of `pred` is akin to that used in [[the hint for last week's `reverse`|assignment2_answers#cps-reverse]]. (Want a further challenge? Define `map2` in the Lambda Calculus, using our right-fold encoding for lists, where `map2 g [a, b, c] [d, e, f]` should evaluate to `[g a d, g b e, g c f]`. Doing this will require drawing on a number of different tools we've developed, including that same strategy for defining `tail`. Purely extra credit.) -- 2.11.0