<p>In practice, the amount of time you have to spend testing each function, to make sure its IO doesn&#39;t trip up in some corner case, is usually greater than the amount of time a rewrite-for-IO would take.</p>
<p>Tom</p>
<div class="gmail_quote">On Jun 28, 2012 2:54 PM, &quot;Dominique Devriese&quot; &lt;<a href="mailto:dominique.devriese@cs.kuleuven.be">dominique.devriese@cs.kuleuven.be</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2012/6/27 Tillmann Rendel &lt;<a href="mailto:rendel@informatik.uni-marburg.de">rendel@informatik.uni-marburg.de</a>&gt;:<br>
&gt; MightyByte wrote:<br>
&gt;&gt;<br>
&gt;&gt; Of course every line of your program that uses a Foo will change if you<br>
&gt;&gt; switch<br>
&gt;&gt; to IO Foo instead.<br>
&gt;<br>
&gt;<br>
&gt; But we often have to also change lines that don&#39;t use Foo at all. For<br>
&gt; example, here is the type of binary trees of integers:<br>
&gt;<br>
&gt; data Tree = Leaf Integer | Branch (Tree Integer) (Tree Integer)<br>
&gt;<br>
&gt; A function to add up all integers in a tree:<br>
&gt;<br>
&gt; amount:: Tree -&gt; Integer<br>
&gt; amount (Leaf x) = x<br>
&gt; amount (Branch t1 t2) = amountt1 + amountt2<br>
&gt;<br>
&gt; All fine so far. Now, consider the following additional requirement: &quot;If the<br>
&gt; command-line flag --multiply is set, the function amount computes the<br>
&gt; product instead of the sum.&quot;<br>
&gt;<br>
&gt; In a language with implicit side effects, it is easy to implement this. We<br>
&gt; just change the third line of the amount function to check whether to call<br>
&gt; (+) or (*). In particular, we would not touch the other two lines.<br>
&gt;<br>
&gt; How would you implement this requirement in Haskell without changing the<br>
&gt; line &quot;amount (Leaf x) = x&quot;?<br>
<br>
I may be missing the point here, but having worked on large code bases<br>
with a wide variety contributors before, I find it very advantageous<br>
that programmers are prevented from writing an amount function whose<br>
behaviour depends on command line arguments without at least an<br>
indication in the type. The fact that the function can not perform<br>
stuff like that is precisely the guarantee that the Haskell type gives<br>
me...<br>
<br>
Dominique<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div>