Skip to content

Commit 496f1d5

Browse files
Merge pull request #1 from patrakov/src
Fix typos in code blocks
2 parents b5e104f + 3892117 commit 496f1d5

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

posts/2021-06-09-getting-to-the-fixed-point.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ If we go one more step, we can see that:
9595

9696
```
9797
factorial 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

103103
From 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
```
241241
Instead of making a recursive call, we introduce a dummy parameter `rec`; when
242242
used 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
532532
And 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

538538
If 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
544544
in 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

Comments
 (0)