part2: typos

This commit is contained in:
Joel Kaasinen
2021-06-21 17:30:57 +03:00
parent 4a2d1f2f5b
commit 0a4bb1fc4e
+2 -2
View File
@@ -4214,7 +4214,7 @@ TODO explain `some` and `many`
<p>We can ask QuickCheck to run them in GHCi:</p> <p>We can ask QuickCheck to run them in GHCi:</p>
<div class="sourceCode" id="cb393"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb393-1" data-line-number="1"><span class="fu">*</span><span class="dt">Examples.QuickCheck</span><span class="fu">&gt;</span> quickCheck propRevSmall</a> <div class="sourceCode" id="cb393"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb393-1" data-line-number="1"><span class="fu">*</span><span class="dt">Examples.QuickCheck</span><span class="fu">&gt;</span> quickCheck propRevSmall</a>
<a class="sourceLine" id="cb393-2" data-line-number="2"><span class="fu">+++</span> <span class="dt">OK</span>, passed <span class="dv">1</span> test<span class="fu">.</span></a></code></pre></div> <a class="sourceLine" id="cb393-2" data-line-number="2"><span class="fu">+++</span> <span class="dt">OK</span>, passed <span class="dv">1</span> test<span class="fu">.</span></a></code></pre></div>
<p>So far so good. However this isn’t really what QuickCheck was made for. QuickCheck was designer for <em>property-based testing</em> where you can state a property your code should have, and QuickCheck runs your code with randomized inputs, checking the property every time. What would be a simple property that a correct implementation of <code>reverse</code> has? Reversing a list twice should certainly give us back the same list. Let’s write it out:</p> <p>So far so good. However this isn’t really what QuickCheck was made for. QuickCheck was designed for <em>property-based testing</em> where you can state a property your code should have, and QuickCheck runs your code with randomized inputs, checking the property every time. What would be a simple property that a correct implementation of <code>reverse</code> has? Reversing a list twice should certainly give us back the same list. Let’s write it out:</p>
<div class="sourceCode" id="cb394"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb394-1" data-line-number="1"><span class="ot">propRevTwice ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Property</span></a> <div class="sourceCode" id="cb394"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb394-1" data-line-number="1"><span class="ot">propRevTwice ::</span> [<span class="dt">Int</span>] <span class="ot">-&gt;</span> <span class="dt">Property</span></a>
<a class="sourceLine" id="cb394-2" data-line-number="2">propRevTwice xs <span class="fu">=</span> reverse (reverse xs) <span class="fu">===</span> xs</a></code></pre></div> <a class="sourceLine" id="cb394-2" data-line-number="2">propRevTwice xs <span class="fu">=</span> reverse (reverse xs) <span class="fu">===</span> xs</a></code></pre></div>
<p>Our <code>Property</code> has an argument, which means that QuickCheck will generate random values and run the test. We can use the <code>verboseCheck</code> function to see which values are run. We can also give a parameter to the test ourselves if we wish to check a specific value.</p> <p>Our <code>Property</code> has an argument, which means that QuickCheck will generate random values and run the test. We can use the <code>verboseCheck</code> function to see which values are run. We can also give a parameter to the test ourselves if we wish to check a specific value.</p>
@@ -4431,7 +4431,7 @@ TODO explain `some` and `many`
<div class="sourceCode" id="cb427"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb427-1" data-line-number="1"><span class="ot">scaleMoney ::</span> <span class="dt">Double</span> <span class="ot">-&gt;</span> <span class="dt">Money</span> currency <span class="ot">-&gt;</span> <span class="dt">Money</span> currency</a> <div class="sourceCode" id="cb427"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb427-1" data-line-number="1"><span class="ot">scaleMoney ::</span> <span class="dt">Double</span> <span class="ot">-&gt;</span> <span class="dt">Money</span> currency <span class="ot">-&gt;</span> <span class="dt">Money</span> currency</a>
<a class="sourceLine" id="cb427-2" data-line-number="2">scaleMoney factor (<span class="dt">Money</span> a) <span class="fu">=</span> <span class="dt">Money</span> (factor <span class="fu">*</span> a)</a></code></pre></div> <a class="sourceLine" id="cb427-2" data-line-number="2">scaleMoney factor (<span class="dt">Money</span> a) <span class="fu">=</span> <span class="dt">Money</span> (factor <span class="fu">*</span> a)</a></code></pre></div>
<div class="sourceCode" id="cb428"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb428-1" data-line-number="1"><span class="fu">*</span><span class="dt">Examples.Phantom</span><span class="fu">&gt;</span> <span class="fu">:</span>t scaleMoney <span class="dv">3</span> twoEuros</a> <div class="sourceCode" id="cb428"><pre class="sourceCode haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb428-1" data-line-number="1"><span class="fu">*</span><span class="dt">Examples.Phantom</span><span class="fu">&gt;</span> <span class="fu">:</span>t scaleMoney <span class="dv">3</span> twoEuros</a>
<a class="sourceLine" id="cb428-2" data-line-number="2">scaleMoney <span class="dv">3</span><span class="ot"> euro ::</span> <span class="dt">Money</span> <span class="dt">EUR</span></a> <a class="sourceLine" id="cb428-2" data-line-number="2">scaleMoney <span class="dv">3</span><span class="ot"> twoEuros ::</span> <span class="dt">Money</span> <span class="dt">EUR</span></a>
<a class="sourceLine" id="cb428-3" data-line-number="3"><span class="fu">*</span><span class="dt">Examples.Phantom</span><span class="fu">&gt;</span> <span class="fu">:</span>t scaleMoney <span class="dv">3</span> dollar</a> <a class="sourceLine" id="cb428-3" data-line-number="3"><span class="fu">*</span><span class="dt">Examples.Phantom</span><span class="fu">&gt;</span> <span class="fu">:</span>t scaleMoney <span class="dv">3</span> dollar</a>
<a class="sourceLine" id="cb428-4" data-line-number="4">scaleMoney <span class="dv">3</span><span class="ot"> dollar ::</span> <span class="dt">Money</span> <span class="dt">USD</span></a></code></pre></div> <a class="sourceLine" id="cb428-4" data-line-number="4">scaleMoney <span class="dv">3</span><span class="ot"> dollar ::</span> <span class="dt">Money</span> <span class="dt">USD</span></a></code></pre></div>
<p>Next up: adding two amounts that are in the same currency. We get a nice type error if we try to add values in two different currencies.</p> <p>Next up: adding two amounts that are in the same currency. We get a nice type error if we try to add values in two different currencies.</p>