Skip to content

Commit e42b3f8

Browse files
committed
MathML
1 parent fb9f84f commit e42b3f8

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

source_md/higher-order-functions.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,16 @@ ghci> scanl (flip (:)) [] [3,2,1]
796796
When using a `scanl`, the final result will be in the last element of the resulting list while a `scanr` will place the result in the head.
797797

798798
Scans are used to monitor the progression of a function that can be implemented as a fold.
799-
Let's answer us this question: **How many elements does it take for the sum of the square roots of all natural numbers to exceed 1000?**
799+
Let's answer us this question: **How many elements does it take for the sum of the square roots of all natural numbers to exceed $1000$?**
800800
To get the square roots of all natural numbers, we just do `map sqrt [1..]`.
801801
Now, to get the sum, we could do a fold, but because we're interested in how the sum progresses, we're going to do a scan.
802-
Once we've done the scan, we just see how many sums are under 1000.
803-
The first sum in the scanlist will be 1, normally.
804-
The second will be 1 plus the square root of 2.
805-
The third will be that plus the square root of 3.
806-
If there are X sums under 1000, then it takes X+1 elements for the sum to exceed 1000.
802+
Once we've done the scan, we just see how many sums are under $1000$.
803+
The first sum in the scanlist will be $1$, normally.
804+
The second will be $1 + \sqrt 2$.
805+
The third will be $1 + \sqrt 2 + \sqrt 3$.
806+
If there are $n$ sums under 1000, then it takes $n + 1$ elements for the sum to exceed $1000$.
807+
808+
807809

808810
```{.haskell:hs}
809811
sqrtSums :: Int
@@ -820,7 +822,7 @@ ghci> sum (map sqrt [1..130])
820822
```
821823

822824
We use `takeWhile` here instead of `filter` because `filter` doesn't work on infinite lists.
823-
Even though we know the list is ascending, `filter` doesn't, so we use `takeWhile` to cut the scanlist off at the first occurrence of a sum greater than 1000.
825+
Even though we know the list is ascending, `filter` doesn't, so we use `takeWhile` to cut the scanlist off at the first occurrence of a sum greater than $1000$.
824826

825827
## Function application with $ {#function-application}
826828

0 commit comments

Comments
 (0)