Skip to content

Commit

Permalink
deploy: 0653a5f
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Oct 29, 2024
1 parent c3935fa commit 388dbe3
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 37 deletions.
10 changes: 5 additions & 5 deletions animation/easing.html
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ <h1 id="easing-functions" class="title">Easing Functions</h1>
.</span><span class="identifier">withRender</span><span>(</span><span class="identifier">r</span><span> =&gt; </span><span class="type-name">Image</span><span>.</span><span class="identifier">circle</span><span>(</span><span class="identifier">r</span><span>))
</span><span class="comment">// bubble: Reactor[Double] = Reactor(
// initial = 0.0,
// onMouseClickHandler = doodle.reactor.Reactor$$$Lambda$14840/0x0000000103a3c040@4c26819f,
// onMouseMoveHandler = doodle.reactor.Reactor$$$Lambda$14841/0x0000000103a3d040@b352d9c,
// onTickHandler = doodle.reactor.Reactor$$$Lambda$14845/0x0000000103a40040@33d457f,
// onMouseClickHandler = doodle.reactor.Reactor$$$Lambda$13993/0x0000000103850040@13c381c8,
// onMouseMoveHandler = doodle.reactor.Reactor$$$Lambda$13994/0x0000000103850840@75f073e0,
// onTickHandler = doodle.reactor.Reactor$$$Lambda$13998/0x0000000103854040@65377bd1,
// tickRate = 100 milliseconds,
// renderHandler = repl.MdocSession$MdocApp$$Lambda$14847/0x0000000103a42040@4bd4cdf9,
// stopHandler = doodle.reactor.Reactor$$$Lambda$14846/0x0000000103a41040@33869765
// renderHandler = repl.MdocSession$MdocApp$$Lambda$14000/0x0000000103855840@6f35ba8,
// stopHandler = doodle.reactor.Reactor$$$Lambda$13999/0x0000000103855040@931477f
// )</span></code></pre>
<div class="flex flex-row justify-between">
<a class="pageNavigation" href="index.html">←Animation and Fireworks</a> <a class="pageNavigation" href="../collections/paths.html">Drawing Paths→</a>
Expand Down
7 changes: 6 additions & 1 deletion expressions/04-types.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,12 @@ <h1 id="types" class="title">Types</h1>
</span><span class="comment">// res0: Int = 3</span></code></pre>
<p>A type of <code>Int</code> means if the expression is successfully evaluated, then the value will be one of the approximately 4.2 billion values the computer understands to be integers. (Integers are also known as &quot;whole numbers&quot;.) </p>
<p>We determine the type of an expression without running it. This means that <em>types are a property of expressions</em>. We can give a type to an expression even if, when we evaluate it, the computation fails. This is also why the type doesn&#39;t tell us the specific value the expression evaluates to: we&#39;d have to evaluate the expression to know that.</p>
<p>Types are worked out in a process known as a <em>type-checking</em>, which is part of <em>compilation</em>. Before a Scala program is run, it must be <em>compiled</em>. Compilation checks that a program makes sense. It must be syntactically correct, meaning it must be written according to the rules of Scala. For example <code>(1 + 2)</code> is syntactically correct, but <code>(1 + 2</code> is not because there is no <code>)</code> to match the <code>(</code>. It must also <em>type check</em>, meaning the types must be correct for the operations we&#39;re trying to do. <code>1 + 2</code> type checks (we are adding integers), but <code>1.toUpperCase</code> does not (there is no concept of upper and lower case for integers.)</p>
<p>Types are worked out in a process known as a <em>type-checking</em>, which is part of <em>compilation</em>. Before a Scala program is run, it must be <em>compiled</em>. Compilation checks that a program makes sense. It must be syntactically correct, meaning it must be written according to the rules of Scala. For example <code>(1 + 2)</code> is syntactically correct, but <code>(1 + 2</code> is not because there is no <code>)</code> to match the <code>(</code>.
Here, &quot;syntax&quot; is the term we use for the rules defining the structure of symbols in a programming language.
In English, we are taught that a sentence can be constructed using the rule: subject + verb + object e.g. &quot;the artist paints a cat&quot;.
A programming language might have a different set of rules and symbols to read <code>Artist.paint(cat);</code>.
This is a general example—languages have syntax variations—and it is worth noting that the English sentence is purely descriptive while the general code example is instructing the computer to paint a cat using &#39;Artist&#39;, which could be a library or object. </p>
<p>It must also <em>type check</em>, meaning the types must be correct for the operations we&#39;re trying to do. <code>1 + 2</code> type checks (we are adding integers), but <code>1.toUpperCase</code> does not (there is no concept of upper and lower case for integers.)</p>
<p>Only programs that successfully compile can be run. We can think of compilation as being analogous to the rules of grammar in writing. The sentence &quot;FaRf fjrmn;l df.fd&quot; is syntactically incorrect in English. The arrangement of letters doesn&#39;t form any words. The sentence &quot;dog flying a here no&quot; is made out of valid words but their arrangement breaks the rules of grammar, which is analogous to the type checks that Scala performs.</p>
<p>It is important to remember that type checking is done before a program runs. If you have used a language like Python or Javascript, which are sometimes called &quot;dynamically typed&quot;, there is no type checking done before a program runs. In a &quot;statically typed&quot; language like Scala the type checking catches some potential errors for us before we run the code. What is sometimes called a type in a dynamically typed language is <em>not</em> a type as we understand it here. Types, for us, exist at the time when a program is compiled, which we will call <em>compile time</em>. At the time when a program runs, which we call <em>run time</em>, we have only values. Values may record some information about the type of the expression that created them. If they do we call these <em>tags</em>, or sometimes <em>boxes</em>. Not all values are tagged or boxed. Avoiding tagging, which is also called <em>type erasure</em>, allows for more efficient programs.</p>
<div class="flex flex-row justify-between">
Expand Down
6 changes: 3 additions & 3 deletions flowers/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -500,17 +500,17 @@ <h4 id="exercise-function-literals">Exercise: Function Literals</h4>
<div class="solution-body">
<p>The first function is</p>
<pre><code class="nohighlight"><span>(</span><span class="identifier">x</span><span>: </span><span class="type-name">Int</span><span>) =&gt; </span><span class="identifier">x</span><span> * </span><span class="identifier">x</span><span>
</span><span class="comment">// res10: Function1[Int, Int] = repl.MdocSession$MdocApp0$$Lambda$15145/0x0000000103ae1840@5e1fdbb5</span></code></pre>
</span><span class="comment">// res10: Function1[Int, Int] = repl.MdocSession$MdocApp0$$Lambda$14298/0x00000001038f1040@3bc430ec</span></code></pre>
<p>The second is</p>
<pre><code class="nohighlight"><span>(</span><span class="identifier">c</span><span>: </span><span class="type-name">Color</span><span>) =&gt; </span><span class="identifier">c</span><span>.</span><span class="identifier">spin</span><span>(</span><span class="number-literal">15</span><span>.</span><span class="identifier">degrees</span><span>)
</span><span class="comment">// res11: Function1[Color, HSLA] = repl.MdocSession$MdocApp0$$Lambda$15146/0x0000000103ae0840@7562c63</span></code></pre>
</span><span class="comment">// res11: Function1[Color, HSLA] = repl.MdocSession$MdocApp0$$Lambda$14299/0x00000001038f0840@2724b87d</span></code></pre>
<p>The third is</p>
<pre><code class="nohighlight"><span>(</span><span class="identifier">image</span><span>: </span><span class="type-name">Image</span><span>) =&gt;
</span><span class="identifier">image</span><span>.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">90</span><span>.</span><span class="identifier">degrees</span><span>))
.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">180</span><span>.</span><span class="identifier">degrees</span><span>))
.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">270</span><span>.</span><span class="identifier">degrees</span><span>))
.</span><span class="identifier">beside</span><span>(</span><span class="identifier">image</span><span>.</span><span class="identifier">rotate</span><span>(</span><span class="number-literal">360</span><span>.</span><span class="identifier">degrees</span><span>))
</span><span class="comment">// res12: Function1[Image, Image] = repl.MdocSession$MdocApp0$$Lambda$15147/0x0000000103b30040@16c8f00a</span></code></pre>
</span><span class="comment">// res12: Function1[Image, Image] = repl.MdocSession$MdocApp0$$Lambda$14300/0x00000001038e7840@78caae5e</span></code></pre>
</div>
</div>
<div class="exercise">
Expand Down
16 changes: 8 additions & 8 deletions generative/flatmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,15 @@ <h4 id="randomness-and-randomness" class="section">Randomness and Randomness {-}
// c = FlatMapped(
// c = FlatMapped(
// c = Suspend(a = RDouble),
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@7eb0f4ef
// f = cats.free.Free$$Lambda$14378/0x00000001038e7840@6d827cf2
// ),
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@61b85210
// f = cats.free.Free$$Lambda$14378/0x00000001038e7840@202091b9
// ),
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@29ec77c9
// f = cats.free.Free$$Lambda$14378/0x00000001038e7840@4479f03a
// ),
// f = repl.MdocSession$MdocApp5$$Lambda$15242/0x0000000103b65040@20da50e
// f = repl.MdocSession$MdocApp5$$Lambda$14395/0x000000010397d040@4cc7933
// ),
// f = repl.MdocSession$MdocApp5$$Lambda$15245/0x0000000103b71840@7b633e2c
// f = repl.MdocSession$MdocApp5$$Lambda$14398/0x000000010397a840@7a57e0b4
// )</span></code></pre>
<p>which makes it clearer that we&#39;re generating three different circles.
&lt;/div&gt;</p>
Expand All @@ -530,17 +530,17 @@ <h4 id="colored-boxes" class="section">Colored Boxes {-}</h4>
</span><span class="type-name">Random</span><span>.</span><span class="identifier">double</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">x</span><span> =&gt; </span><span class="identifier">x</span><span>.</span><span class="identifier">turns</span><span>)
</span><span class="comment">// randomAngle: Free[[A &gt;: Nothing &lt;: Any] =&gt; RandomOp[A], Angle] = FlatMapped(
// c = Suspend(a = RDouble),
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@58e8cb82
// f = cats.free.Free$$Lambda$14378/0x00000001038e7840@5ede1b1e
// )
</span><span>
</span><span class="keyword">val</span><span> </span><span class="identifier">randomColor</span><span>: </span><span class="type-name">Random</span><span>[</span><span class="type-name">Color</span><span>] =
</span><span class="identifier">randomAngle</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">hue</span><span> =&gt; </span><span class="type-name">Color</span><span>.</span><span class="identifier">hsl</span><span>(</span><span class="identifier">hue</span><span>, </span><span class="number-literal">0.7</span><span>, </span><span class="number-literal">0.7</span><span>))
</span><span class="comment">// randomColor: Free[[A &gt;: Nothing &lt;: Any] =&gt; RandomOp[A], Color] = FlatMapped(
// c = FlatMapped(
// c = Suspend(a = RDouble),
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@58e8cb82
// f = cats.free.Free$$Lambda$14378/0x00000001038e7840@5ede1b1e
// ),
// f = cats.free.Free$$Lambda$15225/0x0000000103af3040@1270bd69
// f = cats.free.Free$$Lambda$14378/0x00000001038e7840@55adc8df
// )
</span><span>
</span><span class="keyword">def</span><span> </span><span class="declaration-name">coloredRectangle</span><span>(</span><span class="identifier">color</span><span>: </span><span class="type-name">Color</span><span>): </span><span class="type-name">Image</span><span> =
Expand Down
16 changes: 8 additions & 8 deletions generative/generative.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,29 +345,29 @@ <h1 id="generative-art" class="title">Generative Art</h1>
</tbody>
</table>
<pre><code class="nohighlight"><span class="identifier">math</span><span>.</span><span class="identifier">random</span><span>
</span><span class="comment">// res0: Double = 0.4924912839975709
</span><span class="comment">// res0: Double = 0.7321923153975315
</span><span class="identifier">math</span><span>.</span><span class="identifier">random</span><span>
</span><span class="comment">// res1: Double = 0.14922498513097637</span></code></pre>
</span><span class="comment">// res1: Double = 0.8782656665714154</span></code></pre>
<p>Given <code>math.random</code> we could produce a method that returns a random <code>Angle</code> like so.</p>
<pre><code class="nohighlight"><span class="keyword">def</span><span> </span><span class="declaration-name">randomAngle</span><span>: </span><span class="type-name">Angle</span><span> =
</span><span class="identifier">math</span><span>.</span><span class="identifier">random</span><span>.</span><span class="identifier">turns</span><span>

</span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// res2: Angle = Angle(4.460463406624684)
</span><span class="comment">// res2: Angle = Angle(0.414285054299259)
</span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// res3: Angle = Angle(5.332355554721024)</span></code></pre>
</span><span class="comment">// res3: Angle = Angle(4.071737771399261)</span></code></pre>
<p>Why might we not want to do this? What principle does this break?</p>
<p>&lt;div class=&quot;solution&quot;&gt;
Generating random numbers in this way breaks substitution. Remember substitution says wherever we see an expression we should be able to substitute the value it evaluates to without changing the meaning of the program. Concretely, this means</p>
<pre><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">result1</span><span> = </span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// result1: Angle = Angle(5.201155181755512)
</span><span class="comment">// result1: Angle = Angle(1.2436173182622117)
</span><span class="keyword">val</span><span> </span><span class="identifier">result2</span><span> = </span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// result2: Angle = Angle(2.4967518527825985)</span></code></pre>
</span><span class="comment">// result2: Angle = Angle(4.4462845621989215)</span></code></pre>
<p>and </p>
<pre><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">result1</span><span> = </span><span class="identifier">randomAngle</span><span>
</span><span class="comment">// result1: Angle = Angle(1.1029717333920994)
</span><span class="comment">// result1: Angle = Angle(1.3486939806513423)
</span><span class="keyword">val</span><span> </span><span class="identifier">result2</span><span> = </span><span class="identifier">result1</span><span>
</span><span class="comment">// result2: Angle = Angle(1.1029717333920994)</span></code></pre>
</span><span class="comment">// result2: Angle = Angle(1.3486939806513423)</span></code></pre>
<p>should be the same program and clearly they are not.
&lt;/div&gt;</p>
<p>What should we do? Suffer the slings and arrows of outrageous computational models, or take arms against a sea of side-effects, and by opposing end them! There&#39;s really only one choice.</p>
Expand Down
6 changes: 3 additions & 3 deletions generative/random.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ <h1 id="randomness-without-effect" class="title">Randomness without Effect</h1>
// )</span></code></pre>
<p>No random numbers are actually created until we call the <code>run</code> method.</p>
<pre><code class="nohighlight"><span class="identifier">randomDouble</span><span>.</span><span class="identifier">run</span><span>
</span><span class="comment">// res0: Double = 0.5113098551608625</span></code></pre>
</span><span class="comment">// res0: Double = 0.5642217044601665</span></code></pre>
<p>The type <code>Random[Double]</code> indicates we have something that will produce a random <code>Double</code> when we <code>run</code> it. Just like with <code>Image</code> and <code>draw</code>, substitution holds with <code>Random</code> up until the point we call <code>run</code>.</p>
<p>Table Table generative:random shows some of the ways to construct <code>Random</code> values.</p>
<hr>
Expand Down Expand Up @@ -368,9 +368,9 @@ <h3 id="composing-random" class="section">Composing Random</h3>
</span><span class="type-name">Random</span><span>.</span><span class="identifier">double</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">x</span><span> =&gt; </span><span class="identifier">x</span><span>.</span><span class="identifier">turns</span><span>)</span></code></pre>
<p>When we <code>run</code> <code>RandomAngle</code> we can generate randomly created <code>Angle</code></p>
<pre><code class="nohighlight"><span class="identifier">randomAngle</span><span>.</span><span class="identifier">run</span><span>
</span><span class="comment">// res1: Angle = Angle(4.703122344504545)
</span><span class="comment">// res1: Angle = Angle(3.9249264337729093)
</span><span class="identifier">randomAngle</span><span>.</span><span class="identifier">run</span><span>
</span><span class="comment">// res2: Angle = Angle(1.2369067933139868)</span></code></pre>
</span><span class="comment">// res2: Angle = Angle(4.845887994207942)</span></code></pre>

<h3 id="exercises" class="section">Exercises {-}</h3>

Expand Down
16 changes: 8 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3229,14 +3229,14 @@ $c_Lcycles_Epicycles$.prototype.epicycleTwoWheels__T__V = (function(id) {
var runtime = $m_Lcats_effect_unsafe_IORuntime$().global__Lcats_effect_unsafe_IORuntime();
$f_Ldoodle_interact_animation_Transducer__animate__O__Ldoodle_interact_effect_AnimationRenderer__Ldoodle_effect_Renderer__Ldoodle_interact_algebra_Redraw__s_$less$colon$less__Lcats_effect_unsafe_IORuntime__V(this$19, frame, a, e, r, ev, runtime);
});
$c_Lcycles_Epicycles$.prototype.epicycle = (function(arg) {
var prep0 = $as_T(arg);
this.epicycle__T__V(prep0);
});
$c_Lcycles_Epicycles$.prototype.epicycleTwoWheels = (function(arg) {
var prep0 = $as_T(arg);
this.epicycleTwoWheels__T__V(prep0);
});
$c_Lcycles_Epicycles$.prototype.epicycle = (function(arg) {
var prep0 = $as_T(arg);
this.epicycle__T__V(prep0);
});
var $d_Lcycles_Epicycles$ = new $TypeData().initClass($c_Lcycles_Epicycles$, "cycles.Epicycles$", ({
Lcycles_Epicycles$: 1
}));
Expand Down Expand Up @@ -13138,10 +13138,6 @@ $c_Lpolygons_Creative$.prototype.starPolygonExercise = (function(arg) {
var prep0 = $as_T(arg);
this.starPolygonExercise__T__V(prep0);
});
$c_Lpolygons_Creative$.prototype.bezierCurveAnimation = (function(arg) {
var prep0 = $as_T(arg);
this.bezierCurveAnimation__T__V(prep0);
});
$c_Lpolygons_Creative$.prototype.curvygonExercise = (function(arg) {
var prep0 = $as_T(arg);
this.curvygonExercise__T__V(prep0);
Expand All @@ -13158,6 +13154,10 @@ $c_Lpolygons_Creative$.prototype.concentricExercise = (function(arg) {
var prep0 = $as_T(arg);
this.concentricExercise__T__V(prep0);
});
$c_Lpolygons_Creative$.prototype.bezierCurveAnimation = (function(arg) {
var prep0 = $as_T(arg);
this.bezierCurveAnimation__T__V(prep0);
});
var $d_Lpolygons_Creative$ = new $TypeData().initClass($c_Lpolygons_Creative$, "polygons.Creative$", ({
Lpolygons_Creative$: 1
}));
Expand Down
2 changes: 1 addition & 1 deletion main.js.map

Large diffs are not rendered by default.

0 comments on commit 388dbe3

Please sign in to comment.