Skip to content

## Commit

Merge pull request #1 from patrakov/src
Browse the repository at this point in the history
`Fix typos in code blocks`
• Loading branch information
rebeccaskinner committed Jun 13, 2021
2 parents b5e104f + 3892117 commit 496f1d5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Expand Up @@ -95,9 +95,9 @@ If we go one more step, we can see that:

```
factorial 4 = 4 * (3 * 2 * 1)
factorial 3 = (2 * 2 * 1)
factorial 3 = (3 * 2 * 1)
factorial 4 = 3 * (factorial 3)
factorial 4 = 4 * (factorial 3)
```

From these examples you can start to see the shape of the recursive function
Expand Down Expand Up @@ -236,7 +236,7 @@ rewrite this definition using 'fix',

```haskell
λ fix (\rec n -> if n <= 1 then 1 else n * rec (n-1)) 5
123
120
```
Instead of making a recursive call, we introduce a dummy parameter `rec`; when
used within `fix`, this parameter then refers to `fix`’s argument, hence the
Expand Down Expand Up @@ -532,14 +532,14 @@ fix (\rec n -> if n <= 1 then 1 else n * rec (n - 1)) 5
And that, in turn, becomes:

```haskell
let x = (\rec n -> if n <= 1 then 1 else rec (n - 1)) x in x 5
let x = (\rec n -> if n <= 1 then 1 else n * rec (n - 1)) x in x 5
```

If we apply this function to 5, and replace `n` with `5` we end up with:

```haskell
let x = (\rec 4 ->
if 5 <= 1 then 1 else rec (5 - 1)
let x = (\rec 5 ->
if 5 <= 1 then 1 else 5 * rec (5 - 1)
) x
in x 5
```
Expand All @@ -550,7 +550,7 @@ Following the pattern until we get to our base case, we have:
let x = (\rec 5 ->
if 5 <= 1 then 1 else 5 * rec (5 - 1)
) \$ (\rec' 4 ->
if 4 <= 1 then 1 else 5 * rec' (4 - 1))
if 4 <= 1 then 1 else 4 * rec' (4 - 1))
) \$ (\rec'' 3 ->
if 3 <= 1 then 1 else 3 * rec'' (3 - 1))
) \$ (\rec''' 2 ->
Expand All @@ -569,7 +569,7 @@ and we get:
let x = (\rec 5 ->
if 5 <= 1 then 1 else 5 * rec (5 - 1)
) \$ (\rec' 4 ->
if 4 <= 1 then 1 else 5 * rec' (4 - 1))
if 4 <= 1 then 1 else 4 * rec' (4 - 1))
) \$ (\rec'' 3 ->
if 3 <= 1 then 1 else 3 * rec'' (3 - 1))
) \$ (\rec''' 2 ->
Expand All @@ -584,7 +584,7 @@ Which becomes:
let x = (\rec 5 ->
if 5 <= 1 then 1 else 5 * rec (5 - 1)
) \$ (\rec' 4 ->
if 4 <= 1 then 1 else 5 * rec' (4 - 1))
if 4 <= 1 then 1 else 4 * rec' (4 - 1))
) \$ (\rec'' 3 ->
if 3 <= 1 then 1 else 3 * 2
)
Expand Down

### 0 comments on commit `496f1d5`

Please sign in to comment.