<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Alex,<br><br>That does help, but raises a further question.<br><br>If&nbsp; (&gt;&gt;=) :: m a -&gt; (a -&gt; m b) -&gt; m b<br><br>Then whenever the IO monad is entered it can not be escaped,<br>so in the example you gave:-<br><br>f :: IO a -&gt; Int<br>f _ = 10<br><br><br>while f (putStrLn "foo") is a pure function evaluating to 10,<br>neither the IO Action, nor the a (from 'IO a') can be used without<br>using the (&gt;&gt;=) or (&gt;&gt;). Therefore since the parameter can not<br>be used in the function f without entering the IO monad, your<br>function would be equivalent to :-<br><br>f :: Int<br>f = 10<br><br>I have two questions to try and clarify my understanding.<br><br>1) Is it possible to have a function with an IO Action as an input<br>parameter (and not just ignore the parameter) and have a non-IO<br>return value?<br>(ie is&nbsp;&nbsp;&nbsp;&nbsp;
 f :: IO a -&gt; b&nbsp;&nbsp;&nbsp; possible without ignoring the IO a)<br><br>2) Is it possible to have a function which evaluates any IO Action<br>within the body and have a non-IO return value?<br>(ie is&nbsp;&nbsp;&nbsp; f :: a -&gt; b&nbsp;&nbsp;&nbsp;&nbsp; possible while evaluating any IO Action<br>within the body.)<br><br><br><br>My understanding of Haskell was that both of these situations<br>would not be possible, and the return value would always be<br>of the form IO b. (For these questions I am excluding use of<br>unsafePerformIO)<br><br>Many thanks for your time.<br><br>Adrian.<br><br><br>--- On <b>Sat, 23/1/10, Alexander Dunlap <i>&lt;alexander.dunlap@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Alexander Dunlap &lt;alexander.dunlap@gmail.com&gt;<br>Subject: Re: [Haskell-beginners] Re: Re: testing and the culture of Haskell<br>To: "Adrian
 Adshead" &lt;adrianadshead@yahoo.co.uk&gt;<br>Cc: beginners@haskell.org<br>Date: Saturday, 23 January, 2010, 5:22<br><br><div class="plainMail">When you put actions in a "do" block, what you are really doing under<br>the hood is using the "&gt;&gt;=" function to string actions together. (&gt;&gt;=)<br>:: m a -&gt; (a -&gt; m b) -&gt; m b, so, when m ~ IO, (&gt;&gt;=) :: IO a -&gt; (a -&gt;<br>IO b) -&gt; IO b. Thus, a do block of IO actions will itself be an IO<br>action. However, consider the function:<br><br>f :: IO a -&gt; Int<br>f _ = 10<br><br>Now the value f (putStrLn "foo") is totally pure, and has the value of<br>10. A similar thing is going on with the greetAdrian function.<br><br>Hope that helps.<br><br>Alex<br><br>On Fri, Jan 22, 2010 at 7:34 PM, Adrian Adshead<br>&lt;<a ymailto="mailto:adrianadshead@yahoo.co.uk" href="/mc/compose?to=adrianadshead@yahoo.co.uk">adrianadshead@yahoo.co.uk</a>&gt; wrote:<br>&gt;<br>&gt; OK, so I get the idea that
 all functions are pure because they<br>&gt; just return actions.<br>&gt;<br>&gt; So as I understand it now...<br>&gt;<br>&gt; All functions are pure.<br>&gt; The evaluation of all functions not declared as IO results in no side effects.<br>&gt; The evaluation of all functions declared as IO may or may not have side effects.<br>&gt;<br>&gt; But how can the function greetAdrian from the example below not be an IO<br>&gt; operation?<br>&gt;<br>&gt;<br>&gt;<br>&gt;<br>&gt; From: Maciej Piechotka &lt;uzytkownik2 &lt;at&gt; gmail.com&gt;<br>&gt; Subject: Re: Re: testing and the culture of Haskell<br>&gt; Newsgroups: gmane.comp.lang.haskell.beginners<br>&gt; Date: 2010-01-23 00:31:42 GMT (2 hours and 52 minutes ago)<br>&gt;<br>&gt; On Fri, 2010-01-22 at 20:59 +0000, Adrian Adshead wrote:<br>&gt; &gt; &gt;All Haskell functions are pure without exception.&nbsp; For example:<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;greet :: String -&gt; IO ()<br>&gt; &gt; &gt;greet
 name = putStrLn $ "Hello, "++name<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;This is a pure function from String to IO ().&nbsp; This function (like all<br>&gt; &gt; &gt;Haskell functions) has no side effects.&nbsp; Its return value of type IO ()<br>&gt; &gt; &gt;merely _represents_ an IO action.&nbsp; The runtime system knows how to act<br>&gt; &gt; &gt;on this representation.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;This also means that there is no such thing in Haskell as marking a<br>&gt; &gt; &gt;function as side-effecting.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;This distinction may be subtle, but it's important.<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;Steve<br>&gt; &gt;<br>&gt; &gt; Steve,<br>&gt; &gt;<br>&gt; &gt; Please could you clarify this for me since you are making exactly<br>&gt; &gt; the opposite assertion than I have<br>&gt;&nbsp; understood.<br>&gt; &gt;<br>&gt; &gt; I am confused by you stating "All Haskell functions are pure<br>&gt; &gt;
 without<br>&gt; &gt;&nbsp; exception.".<br>&gt; &gt;<br>&gt; &gt; Pure functions have no impact on 'anything'. They take input<br>&gt; &gt; parameters (which they don't change) and return exactly the<br>&gt; &gt; same result whenever the same input parameters are given.<br>&gt; &gt;<br>&gt; &gt; &gt;greet :: String -&gt; IO ()<br>&gt; &gt; &gt;greet name = putStrLn $ "Hello, "++name<br>&gt; &gt;<br>&gt; &gt; This example you gave is not a pure function since it does have<br>&gt; &gt; the side effect that the screen is changed by outputting the string<br>&gt; &gt; "Hello, " and the name passed in.<br>&gt; &gt;<br>&gt; &gt;<br>&gt;<br>&gt; greatAdrian :: String<br>&gt; greetAdrian = let x = greet "Adrian"<br>&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;in x `seq` f x<br>&gt;<br>&gt; greet can be consider a pure function and value IO () is evaluated by<br>&gt; seq. IO () represents an action(s) not execution of action(s). If f of
 x<br>&gt; does not use any tricks nothing will be<br>&gt;&nbsp; printed.<br>&gt;<br>&gt; IO a value it can be:<br>&gt; - cast unsafely into a. However I guess we omit this shame for a moment<br>&gt; - binded with other action. But the resultant type is now again IO b. So<br>&gt; we still get a something<br>&gt; - returned as main. Then we might consider whole Haskell program as<br>&gt; metalanguage which returns single thing - other program. In similar way<br>&gt; as:<br>&gt;<br>&gt; type PythonProgram = String<br>&gt; main :: PythonProgram<br>&gt; main = "print \"Hello World\""<br>&gt;<br>&gt; is pure add_impure is pure. What we do with the result is other thing.<br>&gt;<br>&gt; Regards<br>&gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; Beginners mailing list<br>&gt; <a ymailto="mailto:Beginners@haskell.org" href="/mc/compose?to=Beginners@haskell.org">Beginners@haskell.org</a><br>&gt; <a
 href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>&gt;<br></div></blockquote></td></tr></table><br>