Skip to content

Commit

Permalink
fix a couple of typos (#71)
Browse files Browse the repository at this point in the history
* fix typo

Signed-off-by: chad3814 <[email protected]>

* be consistent with `square` and `square root`

* fix extra "right" typo, turning it into a playful question

---------

Signed-off-by: chad3814 <[email protected]>
Co-authored-by: Stanislav (Stanley) Modrak <[email protected]>
  • Loading branch information
chad3814 and smith558 authored Sep 20, 2024
1 parent 75ebe3f commit c170c35
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/higher-order-functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ <h1 style="margin-left:-3px">Higher order functions</h1>
[[],[3],[2,3],[1,2,3]]
</pre>
<p>When using a <span class="fixed">scanl</span>, the final result will be in the last element of the resulting list while a <span class="fixed">scanr</span> will place the result in the head.</p>
<p>Scans are used to monitor the progression of a function that can be implemented as a fold. Let's answer us this question: <em>How many elements does it take for the sum of the roots of all natural numbers to exceed 1000?</em> To get the squares of all natural numbers, we just do <span class="fixed">map sqrt [1..]</span>. 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. Once we've done the scan, we just see how many sums are under 1000. The first sum in the scanlist will be 1, normally. The second will be 1 plus the square root of 2. The third will be that plus the square root of 3. If there are X sums under 1000, then it takes X+1 elements for the sum to exceed 1000.</p>
<p>Scans are used to monitor the progression of a function that can be implemented as a fold. Let's answer us this question: <em>How many elements does it take for the sum of the square roots of all natural numbers to exceed 1000?</em> To get the square roots of all natural numbers, we just do <span class="fixed">map sqrt [1..]</span>. 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. Once we've done the scan, we just see how many sums are under 1000. The first sum in the scanlist will be 1, normally. The second will be 1 plus the square root of 2. The third will be that plus the square root of 3. If there are X sums under 1000, then it takes X+1 elements for the sum to exceed 1000.</p>
<pre name="code" class="haskell:hs">
sqrtSums :: Int
sqrtSums = length (takeWhile (&lt;1000) (scanl1 (+) (map sqrt [1..]))) + 1
Expand Down Expand Up @@ -440,7 +440,7 @@ <h1 style="margin-left:-3px">Higher order functions</h1>
sum' :: (Num a) =&gt; [a] -&gt; a
sum' xs = foldl (+) 0 xs
</pre>
<p>The <span class="fixed">xs</span> is exposed on both right sides. Because of currying, we can omit the <span class="fixed">xs</span> on both sides, because calling <span class="fixed">foldl (+) 0</span> creates a function that takes a list. Writing the function as <span class="fixed">sum' = foldl (+) 0</span> is called writing it in point free style. How would we write this in point free style?</p>
<p>The <span class="fixed">xs</span> is exposed on both sides, right? Because of currying, we can omit the <span class="fixed">xs</span> on both sides, because calling <span class="fixed">foldl (+) 0</span> creates a function that takes a list. Writing the function as <span class="fixed">sum' = foldl (+) 0</span> is called writing it in point free style. How would we write this in point free style?</p>
<pre name="code" class="haskell:hs">
fn x = ceiling (negate (tan (cos (max 50 x))))
</pre>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h1 style="display: none;">A guide to Haskell programming language</h1>
</p>
</div>
<p>
Anyone is invited to <em style="color: greenyellow">contribute</em> be either <a class="nostarchlink" href="https://github.com/learnyouahaskell/learnyouahaskell.github.io">opening a pull request</a>
Anyone is invited to <em style="color: greenyellow">contribute</em> by either <a class="nostarchlink" href="https://github.com/learnyouahaskell/learnyouahaskell.github.io">opening a pull request</a>
(preferred) or opening a <a class="nostarchlink" href="https://github.com/learnyouahaskell/learnyouahaskell.github.io/issues/new/choose">content edit request</a> for proposed changes.
</p>
<p>
Expand Down

0 comments on commit c170c35

Please sign in to comment.