<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><pre>>All Haskell functions are pure without exception. For example:<br>><br>>greet :: String -> IO ()<br>>greet name = putStrLn $ "Hello, "++name<br>><br>>This is a pure function from String to IO (). This function (like all<br>>Haskell functions) has no side effects. Its return value of type IO ()<br>>merely _represents_ an IO action. The runtime system knows how to act<br>>on this representation.<br>><br>>This also means that there is no such thing in Haskell as marking a<br>>function as side-effecting.<br>><br>>This distinction may be subtle, but it's important.<br>><br>><br>>Steve<br><br>Steve,<br><br>Please could you clarify this for me since you are making exactly<br>the opposite assertion than I have understood.<br><br>I am confused by you stating "All Haskell functions are pure<br>without
exception.".<br><br>Pure functions have no impact on 'anything'. They take input<br>parameters (which they don't change) and return exactly the<br>same result whenever the same input parameters are given.<br><br>>greet :: String -> IO ()<br>>greet name = putStrLn $ "Hello, "++name<br><br>This example you gave is not a pure function since it does have<br>the side effect that the screen is changed by outputting the string<br>"Hello, " and the name passed in.<br><br>As I understand it the IO in the type signature is the programmers<br>indication to the compiler that the function is not guaranteed to<br>be side effect free.<br><br>add_pure :: Integer -> Integer<br>add_pure x = x + 5<br><br>add_impure :: Integer -> IO Integer<br>add_impure x = return (x + 5)<br><br>add_pure is clearly a pure function. add_impure while it is<br>totally side effect free and therefore fulfills the definition<br>of purity, is impure as far as the compiler is
concerned since<br>I (the programmer) have told the compiler that I do not guarantee<br>that the function is pure.<br><br>Please let me know where I am misunderstanding purity.<br><br>Many thanks<br><br>Adrian.<br></pre></td></tr></table><br>