Skip to content

Commit b2a05b7

Browse files
committed
Update Eff article
1 parent bedfa1c commit b2a05b7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

_site/learn/eff/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h2>Handling Native Effects with the Eff Monad</h2>
5555
<li>Writing/reading to/from local storage</li>
5656
</ul>
5757
<h4 id="the-eff-monad">The Eff Monad</h4>
58-
<p>PureScript’s <code>purescript-eff</code> package defines a monad called <code>Eff</code>, which is used to handle native effects. The goal of the <code>Eff</code> monad is to provide a typed API for effectful computations, while at the same time generating efficient Javascript.</p>
58+
<p>PureScript’s <a href="https://pursuit.purescript.org/packages/purescript-eff/"><code>purescript-eff</code></a> package defines a monad called <code>Eff</code>, which is used to handle native effects. The goal of the <code>Eff</code> monad is to provide a typed API for effectful computations, while at the same time generating efficient Javascript.</p>
5959
<p>Let’s start with an example:</p>
6060
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">module</span> <span class="dt">RandomExample</span> <span class="kw">where</span>
6161

@@ -68,7 +68,7 @@ <h4 id="the-eff-monad">The Eff Monad</h4>
6868
printRandom <span class="fu">=</span> <span class="kw">do</span>
6969
n <span class="ot">&lt;-</span> random
7070
print n</code></pre></div>
71-
<p>This example requires the <code>purescript-console</code> and <code>purescript-random</code> dependencies to be installed:</p>
71+
<p>This example requires the <a href="https://pursuit.purescript.org/packages/purescript-console/"><code>purescript-console</code></a> and <a href="https://pursuit.purescript.org/packages/purescript-random/"><code>purescript-random</code></a> dependencies to be installed:</p>
7272
<pre><code>pulp init
7373
bower install --save purescript-console purescript-random</code></pre>
7474
<p>If you save this file as <code>RandomExample.purs</code>, you will be able to compile and run it using PSCi:</p>
@@ -122,7 +122,7 @@ <h4 id="fine-grained-effects">Fine-Grained Effects</h4>
122122
<h4 id="handlers-and-actions">Handlers and Actions</h4>
123123
<p>Rows of effects can also appear on the left-hand side of a function arrow. This is what differentiates actions like <code>print</code> and <code>random</code> from effect <em>handlers</em>.</p>
124124
<p>While actions <em>add</em> to the set of required effects, a handler <code>subtracts</code> effects from the set.</p>
125-
<p>Consider <code>catchException</code> from the <code>purescript-exceptions</code> package:</p>
125+
<p>Consider <code>catchException</code> from the <a href="https://pursuit.purescript.org/packages/purescript-exceptions/"><code>purescript-exceptions</code></a> package:</p>
126126
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">catchException ::</span> forall a e<span class="fu">.</span> (<span class="dt">Error</span> <span class="ot">-&gt;</span> <span class="dt">Eff</span> e a) <span class="ot">-&gt;</span>
127127
<span class="dt">Eff</span> (<span class="ot">err ::</span> <span class="dt">EXCEPTION</span> <span class="fu">|</span> e) a <span class="ot">-&gt;</span>
128128
<span class="dt">Eff</span> e a</code></pre></div>
@@ -138,10 +138,10 @@ <h4 id="handlers-and-actions">Handlers and Actions</h4>
138138

139139
<span class="kw">import </span><span class="dt">Prelude</span>
140140
<span class="kw">import </span><span class="dt">Control.Monad.Eff</span>
141-
<span class="kw">import </span><span class="dt">Control.Monad.Eff.Error</span>
141+
<span class="kw">import </span><span class="dt">Control.Monad.Eff.Exception</span>
142142

143143
<span class="ot">divide ::</span> forall e<span class="fu">.</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Int</span> <span class="ot">-&gt;</span> <span class="dt">Eff</span> (<span class="ot">err ::</span> <span class="dt">EXCEPTION</span> <span class="fu">|</span> e) <span class="dt">Int</span>
144-
divide _ <span class="dv">0</span> <span class="fu">=</span> throwError <span class="st">&quot;Division by zero&quot;</span>
144+
divide _ <span class="dv">0</span> <span class="fu">=</span> throw <span class="st">&quot;Division by zero&quot;</span>
145145
divide n m <span class="fu">=</span> return (n <span class="fu">/</span> m)</code></pre></div>
146146
<p>If we have already defined this function, we can use the <code>runPure</code> and <code>catchException</code> handlers to define a version of <code>divide</code> which reports its errors using <code>Either</code>:</p>
147147
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="kw">import </span><span class="dt">Data.Either</span>

0 commit comments

Comments
 (0)