Skip to content

Commit 0216c2a

Browse files
author
Gregory Cox
committed
Change " to literal double quote in inline code in 1 location
1 parent 51249bf commit 0216c2a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/input-and-output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ <h1>Input and Output</h1>
10531053
</pre>
10541054
<img src="assets/images/input-and-output/jackofdiamonds.png" alt="jack of diamonds" class="left" width="313" height="280">
10551055
<p>We make a function <span class="fixed">askForNumber</span>, which takes a random number generator and returns an I/O action that will prompt the user for a number and tell him if he guessed it right. In that function, we first generate a random number and a new generator based on the generator that we got as a parameter and call them <span class="fixed">randNumber</span> and <span class="fixed">newGen</span>. Let’s say that the number generated was <span class="fixed">7</span>. Then we tell the user to guess which number we’re thinking of. We perform <span class="fixed">getLine</span> and bind its result to <span class="fixed">numberString</span>. When the user enters <span class="fixed">7</span>, <span class="fixed">numberString</span> becomes <span class="fixed">"7"</span>. Next, we use <span class="fixed">when</span> to check if the string the user entered is an empty string. If it is, an empty I/O action of <span class="fixed">return ()</span> is performed, which effectively ends the program. If it isn’t, the action consisting of that <i>do</i> block right there gets performed. We use <span class="fixed">read</span> on <span class="fixed">numberString</span> to convert it to a number, so <span class="fixed">number</span> is now <span class="fixed">7</span>.</p>
1056-
<div class="hintbox"><b>Excuse me!</b> If the user gives us some input here that <span class="fixed">read</span> can’t read (like <span class="fixed">&quot;haha&quot;</span>), our program will crash with an ugly error message. If you don’t want your program to crash on erroneous input, use <span class="label function">reads</span>, which returns an empty list when it fails to read a string. When it succeeds, it returns a singleton list with a tuple that has our desired value as one component and a string with what it didn’t consume as the other.</div>
1056+
<div class="hintbox"><b>Excuse me!</b> If the user gives us some input here that <span class="fixed">read</span> can’t read (like <span class="fixed">"haha"</span>), our program will crash with an ugly error message. If you don’t want your program to crash on erroneous input, use <span class="label function">reads</span>, which returns an empty list when it fails to read a string. When it succeeds, it returns a singleton list with a tuple that has our desired value as one component and a string with what it didn’t consume as the other.</div>
10571057
<p>We check if the number that we entered is equal to the one generated randomly and give the user the appropriate message. And then we call <span class="fixed">askForNumber</span> recursively, only this time with the new generator that we got, which gives us an I/O action that’s just like the one we performed, only it depends on a different generator and we perform it.</p>
10581058
<p><span class="fixed">main</span> consists of just getting a random generator from the system and calling <span class="fixed">askForNumber</span> with it to get the initial action.</p>
10591059
<p>Here’s our program in action!</p>

0 commit comments

Comments
 (0)