X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=exercises%2Fassignment3_answers.mdwn;h=781649ce504096c76f81ad7a6745eb535c26256b;hp=1fe4baf3807868fe0f93cf387c873e1e70235a8b;hb=a4d2693effe839524592f4427465ff8d97625302;hpb=2f9ea958a1eb9d82d6f8dcad14e9060aeeaf9e4b diff --git a/exercises/assignment3_answers.mdwn b/exercises/assignment3_answers.mdwn index 1fe4baf3..781649ce 100644 --- a/exercises/assignment3_answers.mdwn +++ b/exercises/assignment3_answers.mdwn @@ -43,7 +43,7 @@ > let left_head = \xs. (xs f I) I err in > ... - > Here's another, more straightforward answer. We [[observed before|where?]] that left-folding the `cons` function over a list reverses it. Hence, it is easy to reverse a list defined in terms of its left-fold: + > Here's another, more straightforward answer. We [[observed before|/topics/week2_encodings#flipped-cons]] that left-folding the `cons` function over a list reverses it. Hence, it is easy to reverse a list defined in terms of its left-fold: > let left_empty = \f z. z in ; this the same as for the right-fold encoding of lists > let flipped_left_cons = \xs x. \f z. xs f (f z x) in ; left-folding supplies arguments in a different order than cons expects @@ -238,23 +238,6 @@ Reduce the following forms, if possible: Using the mapping specified in this week's notes, translate the following lambda terms into combinatory logic: - -Let's say that for any lambda term T, [T] is the equivalent Combinatory Logic term. Then we define the [.] mapping as follows. - - 1. [a] = a - 2. [(\aX)] = @a[X] - 3. [(XY)] = ([X][Y]) - -Wait, what is that @a ... business? Well, that's another operation on (a variable and) a CL expression, that we can define like this: - - 4. @aa = I - 5. @aX = KX if a is not in X - 6. @a(Xa) = X if a is not in X - 7. @a(XY) = S(@aX)(@aY) - - - -
  1. [\x x] = @x x = I
  2. [\x y. x] = @x [\y. x] = @x. (@y x) = @x (Kx) = S (@x K) (@x x) = S (KK) I; in general expressions of this form S(KM)I will behave just like M for any expression M @@ -284,6 +267,12 @@ S (S (KS) (S (KK) (S (KS) K))) (KI); this is the B combinator, whi 25. For each of the above translations, how many `I`s are there? Give a rule for describing what each `I` corresponds to in the original lambda term. + This generalization depends on you omitting the translation rule: + + 6. @a(Xa) = X if a is not in X + + > With that shortcut rule omitted, then there turn out to be one `I` in the result corresponding to each occurrence of a bound variable in the original term. + Evaluation strategies in Combinatory Logic ------------------------------------------ @@ -323,8 +312,8 @@ Reduce to beta-normal forms:
    1. (\x. x (\y. y x)) (v w) ~~> v w (\y. y (v w))
    2. (\x. x (\x. y x)) (v w) ~~> v w (\x. y x) -
    3. (\x. x (\y. y x)) (v x) ~~> v w (\y. y (v x)) -
    4. (\x. x (\y. y x)) (v y) ~~> v w (\u. u (v y)) +
    5. (\x. x (\y. y x)) (v x) ~~> v x (\y. y (v x)) +
    6. (\x. x (\y. y x)) (v y) ~~> v y (\u. u (v y))
    7. (\x y. x y y) u v ~~> u v v
    8. (\x y. y x) (u v) z w ~~> z (u v) w