<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">OK, so I get the idea that all functions are pure because they<br>just return actions.<br><br>So as I understand it now...<br><br>All functions are pure.<br>The evaluation of all functions not declared as IO results in no side effects.<br>The evaluation of all functions declared as IO may or may not have side effects.<br><br>But how can the function greetAdrian from the example below not be an IO<br>operation?<br><br><br><br><br>From: Maciej Piechotka &lt;uzytkownik2 &lt;at&gt; gmail.com&gt;<br>
Subject: <a target="_top" rel="nofollow" href="http://news.gmane.org/find-root.php?message_id=%3c1264206701.5563.13.camel%40picard%3e">Re: Re: testing and the culture of Haskell</a><br>
Newsgroups: <a href="http://news.gmane.org/gmane.comp.lang.haskell.beginners" target="_top">gmane.comp.lang.haskell.beginners</a><br>
Date: 2010-01-23 00:31:42 GMT
 (2 hours and 52 minutes ago)<br>
<pre>On Fri, 2010-01-22 at 20:59 +0000, Adrian Adshead wrote:<br>&gt; &gt;All Haskell functions are pure without exception.  For example:<br>&gt; &gt;<br>&gt; &gt;greet :: String -&gt; IO ()<br>&gt; &gt;greet name = putStrLn $ "Hello, "++name<br>&gt; &gt;<br>&gt; &gt;This is a pure function from String to IO ().  This function (like all<br>&gt; &gt;Haskell functions) has no side effects.  Its return value of type IO ()<br>&gt; &gt;merely _<u>represents</u>_ an IO action.  The runtime system knows how to act<br>&gt; &gt;on this representation.<br>&gt; &gt;<br>&gt; &gt;This also means that there is no such thing in Haskell as marking a<br>&gt; &gt;function as side-effecting.<br>&gt; &gt;<br>&gt; &gt;This distinction may be subtle, but it's important.<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;Steve<br>&gt; <br>&gt; Steve,<br>&gt; <br>&gt; Please could you clarify this for me since you are making exactly<br>&gt; the opposite assertion than I have
 understood.<br>&gt; <br>&gt; I am confused by you stating "All Haskell functions are pure<br>&gt; without<br>&gt;  exception.".<br>&gt; <br>&gt; Pure functions have no impact on 'anything'. They take input<br>&gt; parameters (which they don't change) and return exactly the<br>&gt; same result whenever the same input parameters are given.<br>&gt; <br>&gt; &gt;greet :: String -&gt; IO ()<br>&gt; &gt;greet name = putStrLn $ "Hello, "++name<br>&gt; <br>&gt; This example you gave is not a pure function since it does have<br>&gt; the side effect that the screen is changed by outputting the string<br>&gt; "Hello, " and the name passed in.<br>&gt; <br>&gt; <br><br>greatAdrian :: String<br>greetAdrian = let x = greet "Adrian"<br>              in x `seq` f x<br><br>greet can be consider a pure function and value IO () is evaluated by<br>seq. IO () represents an action(s) not execution of action(s). If f of x<br>does not use any tricks nothing will be
 printed.<br><br>IO a value it can be:<br>- cast unsafely into a. However I guess we omit this shame for a moment<br>- binded with other action. But the resultant type is now again IO b. So<br>we still get a something <br>- returned as main. Then we might consider whole Haskell program as<br>metalanguage which returns single thing - other program. In similar way<br>as:<br><br>type PythonProgram = String<br>main :: PythonProgram<br>main = "print \"Hello World\""<br><br>is pure add_impure is pure. What we do with the result is other thing.<br><br>Regards<br><br></pre></td></tr></table><br>