title: Understanding pure functions in Haskell with IO
body: <p>Given a Haskell <strong>value</strong> (edit per <a href="https://stackoverflow.com/users/2225384/rein-henrichs">Rein Heinrich</a>'s <a href="https://stackoverflow.com/questions/34280735/understanding-pure-functions-in-haskell-w-io?noredirect=1#comment56312971_34280735">comment</a>) <code>f</code>:</p>
  
  <pre><code>f :: IO Int
  f = ... -- ignoring its implementation
  </code></pre>
  
  <p>Quoting "Type-Driven Development with Idris,"</p>
  
  <blockquote>
    <p>The key property of a pure function is that the same inputs always produce the same result. This property is known as referential transparency</p>
  </blockquote>
  
  <p>Is <code>f</code>, and, namely all <code>IO ...</code> functions in Haskell, pure? It seems to me that they are not since, <code>lookInDatabase :: IO DBThing</code>, won't <strong>always</strong> return the same value since:</p>
  
  <ul>
  <li>at t=0, the DB might be down</li>
  <li>at t=1, the DB might be up and <code>return MyDbThing</code> would result</li>
  </ul>
  
  <p>In short, is <code>f</code> (and <code>IO ...</code> functions in general) pure? If yes, then please correct my incorrect understanding given my attempt to disprove the functional purity of <code>f</code> with my <code>t=...</code> examples.</p>