Skip to content

Commit 501c167

Browse files
author
Gregory Cox
committed
Replace raw characters with entities (e.g. <) in code blocks
1 parent 0216c2a commit 501c167

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

docs/functors-applicative-functors-and-monoids.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ <h1>Functors, Applicative Functors and Monoids</h1>
576576
</p>
577577

578578
<pre name="code" class="haskell:hs">
579-
ghci&gt; [(+1),(*100),(*5)] <*> [1,2,3]
579+
ghci&gt; [(+1),(*100),(*5)] &lt;*&gt; [1,2,3]
580580
[2,3,4,100,200,300,5,10,15]
581581
</pre>
582582

@@ -598,7 +598,7 @@ <h1>Functors, Applicative Functors and Monoids</h1>
598598
</p>
599599

600600
<pre name="code" class="haskell:hs">
601-
ghci&gt; getZipList $ ZipList [(+1),(*100),(*5)] <*> ZipList [1,2,3]
601+
ghci&gt; getZipList $ ZipList [(+1),(*100),(*5)] &lt;*&gt; ZipList [1,2,3]
602602
[2,200,15]
603603
</pre>
604604

@@ -1501,7 +1501,7 @@ <h3><span class="fixed">Any</span> and <span class="fixed">All</span></h3>
15011501

15021502
<p>
15031503
The other way for <span class="fixed">Bool</span> to be an instance of
1504-
<span class="fixed">Monoid</span> is to kind of do the opposite: have <span class="fixed">&&</span>
1504+
<span class="fixed">Monoid</span> is to kind of do the opposite: have <span class="fixed">&amp;&amp;</span>
15051505
be the binary function and then make <span class="fixed">True</span>
15061506
the identity value. Logical <i>and</i> will return <span class="fixed">True</span> only
15071507
if both of its parameters are <span class="fixed">True</span>. This is the <i>newtype</i>
@@ -1520,7 +1520,7 @@ <h3><span class="fixed">Any</span> and <span class="fixed">All</span></h3>
15201520
<pre name="code" class="haskell:hs">
15211521
instance Monoid All where
15221522
mempty = All True
1523-
All x `mappend` All y = All (x && y)
1523+
All x `mappend` All y = All (x &amp;&amp; y)
15241524
</pre>
15251525

15261526
<p>

docs/making-our-own-types-and-typeclasses.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h1>Making Our Own Types and Typeclasses</h1>
9595
</pre>
9696
<p>Notice that when defining a point, we used the same name for the data type and the value constructor. This has no special meaning, although it’s common to use the same name as the type if there’s only one value constructor. So now the <span class="fixed">Circle</span> has two fields, one is of type <span class="fixed">Point</span> and the other of type <span class="fixed">Float</span>. This makes it easier to understand what’s what. Same goes for the rectangle. We have to adjust our <span class="fixed">surface</span> function to reflect these changes.</p>
9797
<pre name="code" class="haskell:hs">
98-
surface :: Shape -> Float
98+
surface :: Shape -&gt; Float
9999
surface (Circle _ r) = pi * r ^ 2
100100
surface (Rectangle (Point x1 y1) (Point x2 y2)) = (abs $ x2 - x1) * (abs $ y2 - y1)
101101
</pre>
@@ -421,7 +421,7 @@ <h1>Making Our Own Types and Typeclasses</h1>
421421
ghci&gt; Just 100 &gt; Just 50
422422
True
423423
</pre>
424-
<p>But we can’t do something like <span class="fixed">Just (*3) > Just (*2)</span>, because <span class="fixed">(*3)</span> and <span class="fixed">(*2)</span> are functions, which aren’t instances of <span class="fixed">Ord</span>.</p>
424+
<p>But we can’t do something like <span class="fixed">Just (*3) &gt; Just (*2)</span>, because <span class="fixed">(*3)</span> and <span class="fixed">(*2)</span> are functions, which aren’t instances of <span class="fixed">Ord</span>.</p>
425425
<p>We can easily use algebraic data types to make enumerations and the <span class="fixed">Enum</span> and <span class="fixed">Bounded</span> typeclasses help us with that. Consider the following data type:</p>
426426
<pre name="code" class="haskell:hs">
427427
data Day = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
@@ -681,7 +681,7 @@ <h1>Making Our Own Types and Typeclasses</h1>
681681
treeElem x EmptyTree = False
682682
treeElem x (Node a left right)
683683
| x == a = True
684-
| x < a = treeElem x left
684+
| x &lt; a = treeElem x left
685685
| x &gt; a = treeElem x right
686686
</pre>
687687
<p>All we had to do was write up the previous paragraph in code. Let’s have some fun with our trees! Instead of manually building one (although we could), we’ll use a fold to build up a tree from a list. Remember, pretty much everything that traverses a list one by one and then returns some sort of value can be implemented with a fold! We’re going to start with the empty tree and then approach a list from the right and just insert element after element into our accumulator tree. </p>

docs/modules.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,21 @@ <h1>Modules</h1>
168168
</pre>
169169
<p>Say we wanted to know the sum of all third powers that are under 10,000. We can’t map <span class="fixed">(^3)</span> to <span class="fixed">[1..]</span>, apply a filter and then try to sum that up because filtering an infinite list never finishes. You may know that all the elements here are ascending but Haskell doesn’t. That’s why we can do this:</p>
170170
<pre name="code" class="haskell:ghci">
171-
ghci&gt; sum $ takeWhile (<10000) $ map (^3) [1..]
171+
ghci&gt; sum $ takeWhile (&lt;10000) $ map (^3) [1..]
172172
53361
173173
</pre>
174174
<p>We apply <span class="fixed">(^3)</span> to an infinite list and then once an element that’s over 10,000 is encountered, the list is cut off. Now we can sum it up easily.</p>
175175
<p><span class="label function">dropWhile</span> is similar, only it drops all the elements while the predicate is true. Once predicate equates to <span class="fixed">False</span>, it returns the rest of the list. An extremely useful and lovely function!</p>
176176
<pre name="code" class="haskell:ghci">
177177
ghci&gt; dropWhile (/=&#39; &#39;) &quot;This is a sentence&quot;
178178
&quot; is a sentence&quot;
179-
ghci&gt; dropWhile (<3) [1,2,2,2,3,4,5,4,3,2,1]
179+
ghci&gt; dropWhile (&lt;3) [1,2,2,2,3,4,5,4,3,2,1]
180180
[3,4,5,4,3,2,1]
181181
</pre>
182182
<p>We’re given a list that represents the value of a stock by date. The list is made of tuples whose first component is the stock value, the second is the year, the third is the month and the fourth is the date. We want to know when the stock value first exceeded one thousand dollars!</p>
183183
<pre name="code" class="haskell:ghci">
184184
ghci&gt; let stock = [(994.4,2008,9,1),(995.2,2008,9,2),(999.2,2008,9,3),(1001.4,2008,9,4),(998.3,2008,9,5)]
185-
ghci&gt; head (dropWhile (\(val,y,m,d) -&gt; val < 1000) stock)
185+
ghci&gt; head (dropWhile (\(val,y,m,d) -&gt; val &lt; 1000) stock)
186186
(1001.4,2008,9,4)
187187
</pre>
188188
<p><span class="label function">span</span> is kind of like <span class="fixed">takeWhile</span>, only it returns a pair of lists. The first list contains everything the resulting list from <span class="fixed">takeWhile</span> would contain if it were called with the same predicate and the same list. The second list contains the part of the list that would have been dropped.</p>

docs/recursion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h1 style="margin-left:-2px">Recursion</h1>
6666
<pre name="code" class="haskell:hs">
6767
replicate&#39; :: (Num i, Ord i) =&gt; i -&gt; a -&gt; [a]
6868
replicate&#39; n x
69-
| n <= 0 = []
69+
| n &lt;= 0 = []
7070
| otherwise = x:replicate&#39; (n-1) x
7171
</pre>
7272
<p>We used guards here instead of patterns because we’re testing for a boolean condition. If <span class="fixed">n</span> is less than or equal to 0, return an empty list. Otherwise return a list that has <span class="fixed">x</span> as the first element and then <span class="fixed">x</span> replicated n-1 times as the tail. Eventually, the <span class="fixed">(n-1)</span> part will cause our function to reach the edge condition.</p>

docs/starting-out.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,13 @@ <h1 style="margin-left:-3px">Starting Out</h1>
415415
</p>
416416
<p>If we wanted to write that in Haskell, we could do something like <span class="fixed">take 10 [2,4..]</span>. But what if we didn’t want doubles of the first 10 natural numbers but some kind of more complex function applied on them? We could use a list comprehension for that. List comprehensions are very similar to set comprehensions. We’ll stick to getting the first 10 even numbers for now. The list comprehension we could use is <span class="fixed">[x*2 | x &lt;- [1..10]]</span>. <span class="fixed">x</span> is drawn from <span class="fixed">[1..10]</span> and for every element in <span class="fixed">[1..10]</span> (which we have bound to <span class="fixed">x</span>), we get that element, only doubled. Here’s that comprehension in action. </p>
417417
<pre name="code" class="haskell: ghci">
418-
ghci&gt; [x*2 | x <- [1..10]]
418+
ghci&gt; [x*2 | x &lt;- [1..10]]
419419
[2,4,6,8,10,12,14,16,18,20]
420420
</pre>
421421
<p>As you can see, we get the desired results. Now let’s add a condition (or a predicate) to that comprehension. Predicates go after the binding parts and are separated from them by a comma. Let’s say we want only the elements which, doubled, are greater than or equal to 12.
422422
</p>
423423
<pre name="code" class="haskell: ghci">
424-
ghci&gt; [x*2 | x <- [1..10], x*2 >= 12]
424+
ghci&gt; [x*2 | x &lt;- [1..10], x*2 &gt;= 12]
425425
[12,14,16,18,20]
426426
</pre>
427427
<p>Cool, it works. How about if we wanted all numbers from 50 to 100 whose remainder when divided with the number 7 is 3? Easy.</p>

docs/syntax-in-functions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h1 style="margin-left:-3px">Syntax in Functions</h1>
106106
<p>Which reminds me, you can also pattern match in list comprehensions. Check this out:</p>
107107
<pre name="code" class="haskell: ghci">
108108
ghci&gt; let xs = [(1,3), (4,3), (2,4), (5,3), (5,6), (3,1)]
109-
ghci&gt; [a+b | (a,b) <- xs]
109+
ghci&gt; [a+b | (a,b) &lt;- xs]
110110
[4,7,6,8,11,4] </pre>
111111
<p>
112112
Should a pattern match fail, it will just move on to the next element.

0 commit comments

Comments
 (0)