12ddbd6bd9a59bf1d4cb53dee2b15f103cf594ff
[lambda.git] / hints / assignment_4_hint_3_alternate_1.mdwn
1 Alternate strategy for Y1, Y2
2
3 *       This is (in effect) the strategy used by OCaml. The mutually recursive:
4
5         let rec
6                 f x = A  ; A may refer to f or g
7         and
8                 g y = B  ; B may refer to f or g
9         in
10                 C
11
12 is implemented using regular, non-mutual recursion, like this (`f'` is a variable not occurring free in `A`, `B`, or `C`):
13
14         let rec f' g x = (let f = f' g in A)
15         in let rec g y = (let f = f' g in B)
16         in let f = f' g in C
17
18 or, expanded into the form we've been working with:
19
20         let f' = Y (\f' g x. (\f. A) (f' g)) in
21         let g  = Y (\g y. (\f. B) (f' g)) in
22         let f  = f' g
23