<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 16 Feb 2008, at 11:40 PM, Peter Verswyvelen wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"> <font face="Helvetica, Arial, sans-serif">After having played with some packages that use arrows, and after having read the very nice "programming with arrows" paper I wanted to build some of my own.<br> <br> Strangely my code did not work, even the simplest function got stuck in an infinite loop or gave a stack overflow.<br> <br> I quickly noticed I made a really stupid mistake, I forget to implement "arr"! However, the compiler did not give a warning on this. So I wandered how it was possible that the Arrow package had a default implementation for something so specific as arr?<br> <br> The code revealed the following:<br> <br> </font> <pre>        <span class="comment">-- | Lift a function to an arrow: you must define either this</span>
        <span class="comment">--   or 'pure'.</span>
        <span class="varid">arr</span> <span class="keyglyph">::</span> <span class="layout">(</span><span class="varid">b</span> <span class="keyglyph">-&gt;</span> <span class="varid">c</span><span class="layout">)</span> <span class="keyglyph">-&gt;</span> <span class="varid">a</span> <span class="varid">b</span> <span class="varid">c</span>
        <span class="varid">arr</span> <span class="keyglyph">=</span> <span class="varid">pure</span>

        <span class="comment">-- | A synonym for 'arr': you must define one or other of them.</span>
        <span class="varid">pure</span> <span class="keyglyph">::</span> <span class="layout">(</span><span class="varid">b</span> <span class="keyglyph">-&gt;</span> <span class="varid">c</span><span class="layout">)</span> <span class="keyglyph">-&gt;</span> <span class="varid">a</span> <span class="varid">b</span> <span class="varid">c</span>
        <span class="varid">pure</span> <span class="keyglyph">=</span> <span class="varid">arr</span></pre> <font face="Helvetica, Arial, sans-serif">Ah, so the default implementation of arr is pure... and vice versa...<br> <br> This feels like rather incorrect to me, but my feelings are based on imperative background knowledge, so this might be totally correct design in Haskell.<br> </font><font face="Helvetica, Arial, sans-serif"><br> Why not force people to implement arr and leave just pure as the synonym? And if pure is really a synonym for arr, what does it do inside the Arrow type class? Does it ever make sense to have a different implementation for arr and pure?</font></blockquote><div><br class="webkit-block-placeholder"></div><div>No; the equations arr = pure and pure = arr are laws for the class.  (This is true in general for default methods).</div><div><br class="webkit-block-placeholder"></div><div>Note that this situation --- where leaving the default methods in place gives rise to an infinite loop --- is quite common; it occurs for the classes Eq and Ord, as well, for example.  This example is admittedly kind of silly, but I'm sure someone has a passionate attachment to one or both names, so requiring definitions to use one or the other would be controversial.</div><div><br class="webkit-block-placeholder"></div><div>jcc</div><div><br class="webkit-block-placeholder"></div></div></body></html>