title: A Haskell function of type: IO String-> String
body: <p>I wrote a bunch of code in Haskell to create an index of a text. The top function looks like this:</p>
  
  <pre><code>index :: String -&gt; [(String, [Integer])]
  index a = [...]
  </code></pre>
  
  <p>Now I want to give this function a String read from a file:</p>
  
  <pre><code>index readFile "input.txt"
  </code></pre>
  
  <p>Which won't work because readFile is of type FilePath -> IO String.</p>
  
  <blockquote>
    <p>Couldn't match expected type 'String'
    against inferred type 'IO String'</p>
  </blockquote>
  
  <p>I see the error, but I can't find any function with type:</p>
  
  <pre><code>IO String -&gt; String
  </code></pre>
  
  <p>I guess the key to success lies somewhere under some Monads, but I could not find a way to solve my problem.</p>