<div dir="ltr"><div style="text-align: left;">
<div style="text-align: center;">
<div style="text-align: left;"><font style="font-family: arial,sans-serif;" size="2">&gt;&gt; Is there any good tutorial on arrows?</font><font size="2"><br></font>&gt; Ross Paterson. Arrows and Computation.<br>
&gt; <a href="http://www.soi.city.ac.uk/%7Eross/papers/fop.html" target="_blank">http://www.soi.city.ac.uk/~ross/papers/fop.html</a><br style="font-family: arial,sans-serif;"><font size="2">
<br style="font-family: arial,sans-serif;">
</font><font style="font-family: arial,sans-serif;" size="2">If you&#39;re
new to Haskell, I&#39;m guessing you&#39;re looking at the instance of Arrow
for ordinary functions, so that you can write in the point-free style.</font><font size="2"><br style="font-family: arial,sans-serif;">
<br style="font-family: arial,sans-serif;">
<span style="font-family: courier new,monospace;" class="keyword">instance</span></font><font style="font-family: courier new,monospace;" size="2"> <span class="conid">Arrow</span> <span class="layout">(</span><span class="keyglyph">-&gt;</span><span class="layout">)</span> <span class="keyword">where</span></font><font style="font-family: courier new,monospace;" size="2"><br>

</font><font style="font-family: courier new,monospace;" size="2"><a name="(line119)"></a>&nbsp; <span class="varid">arr</span> <span class="varid">f</span> <span class="keyglyph">=</span> <span class="varid">f</span></font><font style="font-family: courier new,monospace;" size="2"><br>

</font><font style="font-family: courier new,monospace;" size="2"><a name="(line120)"></a>&nbsp;        <span class="varid">f</span> <span class="varop">&gt;&gt;&gt;</span> <span class="varid">g</span> <span class="keyglyph">=</span> <span class="varid">g</span> <span class="varop">.</span> <span class="varid">f</span></font><font style="font-family: courier new,monospace;" size="2"><br>

</font><font style="font-family: courier new,monospace;" size="2"><a name="(line121)"></a>&nbsp;        <span class="varid">first</span> <span class="varid">f</span> <span class="keyglyph">=</span> <span class="varid">f</span> <span class="varop">***</span> <span class="varid">id</span></font><font style="font-family: courier new,monospace;" size="2"><br>

</font><font style="font-family: courier new,monospace;" size="2"><a name="(line122)"></a>&nbsp;        <span class="varid">second</span> <span class="varid">f</span> <span class="keyglyph">=</span> <span class="varid">id</span> <span class="varop">***</span> <span class="varid">f</span></font><font style="font-family: courier new,monospace;" size="2"><br>

</font><font style="font-family: courier new,monospace;" size="2"><a name="(line123)"></a><span class="comment"></span><a name="(line125)"></a>&nbsp;        <span class="layout">(</span><span class="varop">***</span><span class="layout">)</span> <span class="varid">f</span> <span class="varid">g</span> <span class="keyglyph">~</span><span class="layout">(</span><span class="varid">x</span><span class="layout">,</span><span class="varid">y</span><span class="layout">)</span> <span class="keyglyph">=</span> <span class="layout">(</span><span class="varid">f</span> <span class="varid">x</span><span class="layout">,</span> <span class="varid">g</span> <span class="varid">y</span><span class="layout">)</span></font><font size="2"><br style="font-family: arial,sans-serif;">

<br style="font-family: arial,sans-serif;">
<br style="font-family: arial,sans-serif;">
</font><font style="font-family: arial,sans-serif;" size="2">If so, Ross Paterson&#39;s paper may scare you off.&nbsp; I&#39;m not aware of any good tutorial for ordinary functions - maybe because using arrows this way is sort of a point-free programming gimmick.&nbsp; Anyway, here&#39;s my attempt at a quick tutorial of the Arrow combinators for ordinary functions.<br>

<br></font><font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;">-- Pass input to one function, then its output to another</span></font><br><font style="font-family: arial,sans-serif;" size="2">
<span style="font-family: courier new,monospace;">(f &gt;&gt;&gt; g) x == g (f x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br></span></font><font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;">-- Pass two inputs to two functions</span></font><br style="font-family: courier new,monospace;">
<font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;"></span>
<span style="font-family: courier new,monospace;">(f *** g) ~(x,y) == (f x, g y) <br><br></span></font><font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;">-- Pass one input to both functions</span></font><br style="font-family: courier new,monospace;">
<font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;"></span>
<span style="font-family: courier new,monospace;">(f &amp;&amp;&amp; g) x == (f x, g x)<br><br></span></font><font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;">-- Apply function to only first of two inputs</span></font><br style="font-family: courier new,monospace;">
<font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;"></span>
<span style="font-family: courier new,monospace;">(first f) (x,y) == (f x, y) </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"><br></span></font><font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;">-- Apply function to only second of two inputs</span></font><br>
<font style="font-family: arial,sans-serif;" size="2"><span style="font-family: courier new,monospace;">(second f) (x,y) == (x, f y)</span><br>
<br>
The pictures on this page are helpful:<br>
</font></div>
<span class="keyword"></span></div>
</div>

<br>
<font style="font-family: arial,sans-serif;" size="2">Arrows are more interesting when composing more abstract things </font>where it doesn&#39;t make sense to give the user access to inputs and outputs, such as modeling circuits where the inputs are wires.&nbsp; Lots of good examples in the paper apfelmus recommended.<br>
<br>-Greg<br>
<br><br><br><div class="gmail_quote">On Fri, Jul 18, 2008 at 1:33 AM, apfelmus wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">
Rafael Gustavo da Cunha Pereira Pinto wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is there any good tutorial on arrows?<br>
</blockquote>
<br></div>
I found<br>
<br>
&nbsp;Ross Paterson. Arrows and Computation.<br>
&nbsp;<a href="http://www.soi.city.ac.uk/%7Eross/papers/fop.html" target="_blank">http://www.soi.city.ac.uk/~ross/papers/fop.html</a><br>
<br>
to be pretty good.<br>
<br>
<br>
Regards,<br><font color="#888888">
apfelmus</font><div><div></div><div class="Wj3C7c"><br>
<br>
_______________________________________________<br>
Beginners mailing list<br>