@@ -95,9 +95,9 @@ If we go one more step, we can see that:
9595
9696```
9797factorial 4 = 4 * (3 * 2 * 1)
98- factorial 3 = (2 * 2 * 1)
98+ factorial 3 = (3 * 2 * 1)
9999
100- factorial 4 = 3 * (factorial 3)
100+ factorial 4 = 4 * (factorial 3)
101101```
102102
103103From these examples you can start to see the shape of the recursive function
@@ -236,7 +236,7 @@ rewrite this definition using 'fix',
236236
237237``` haskell
238238λ fix (\ rec n -> if n <= 1 then 1 else n * rec (n- 1 )) 5
239- 123
239+ 120
240240```
241241Instead of making a recursive call, we introduce a dummy parameter ` rec ` ; when
242242used within ` fix ` , this parameter then refers to ` fix ` ’s argument, hence the
@@ -532,14 +532,14 @@ fix (\rec n -> if n <= 1 then 1 else n * rec (n - 1)) 5
532532And that, in turn, becomes:
533533
534534``` haskell
535- let x = (\ rec n -> if n <= 1 then 1 else rec (n - 1 )) x in x 5
535+ let x = (\ rec n -> if n <= 1 then 1 else n * rec (n - 1 )) x in x 5
536536```
537537
538538If we apply this function to 5, and replace ` n ` with ` 5 ` we end up with:
539539
540540``` haskell
541- let x = (\ rec 4 ->
542- if 5 <= 1 then 1 else rec (5 - 1 )
541+ let x = (\ rec 5 ->
542+ if 5 <= 1 then 1 else 5 * rec (5 - 1 )
543543 ) x
544544in x 5
545545```
@@ -550,7 +550,7 @@ Following the pattern until we get to our base case, we have:
550550 let x = (\ rec 5 ->
551551 if 5 <= 1 then 1 else 5 * rec (5 - 1 )
552552 ) $ (\ rec' 4 ->
553- if 4 <= 1 then 1 else 5 * rec' (4 - 1 ))
553+ if 4 <= 1 then 1 else 4 * rec' (4 - 1 ))
554554 ) $ (\ rec'' 3 ->
555555 if 3 <= 1 then 1 else 3 * rec'' (3 - 1 ))
556556 ) $ (\ rec''' 2 ->
@@ -569,7 +569,7 @@ and we get:
569569 let x = (\ rec 5 ->
570570 if 5 <= 1 then 1 else 5 * rec (5 - 1 )
571571 ) $ (\ rec' 4 ->
572- if 4 <= 1 then 1 else 5 * rec' (4 - 1 ))
572+ if 4 <= 1 then 1 else 4 * rec' (4 - 1 ))
573573 ) $ (\ rec'' 3 ->
574574 if 3 <= 1 then 1 else 3 * rec'' (3 - 1 ))
575575 ) $ (\ rec''' 2 ->
@@ -584,7 +584,7 @@ Which becomes:
584584 let x = (\ rec 5 ->
585585 if 5 <= 1 then 1 else 5 * rec (5 - 1 )
586586 ) $ (\ rec' 4 ->
587- if 4 <= 1 then 1 else 5 * rec' (4 - 1 ))
587+ if 4 <= 1 then 1 else 4 * rec' (4 - 1 ))
588588 ) $ (\ rec'' 3 ->
589589 if 3 <= 1 then 1 else 3 * 2
590590 )
0 commit comments