title: Haskell Curl Help
body: <p>Ok, I'm trying to wrap my head around IO in Haskell, and I figured I'd write a short little app dealing with web pages to do it. The snippet I'm getting tripped up at is (with apologies to <a href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">bobince</a>, though to be fair, I'm not trying to <em>parse</em> HTML here, just extract one or two values):</p>
  
  <pre><code>titleFromUrl url = do
      (_, page) &lt;- curlGetString url [CurlTimeout 60]   
      matchRegex (mkRegexWithOpts "&lt;title&gt;(.*?)&lt;/title&gt;" False True) page
  </code></pre>
  
  <p>The above should take a URL in string form, scan the page it points to with <code>matchRegex</code>, and return either <code>Nothing</code> or <code>Just [a]</code>, where <code>a</code> is the matched (possibly multi-line) string. The frustrating thing is that when I try doing</p>
  
  <pre><code>Prelude&gt; (_, page) &lt;- curlGetString url [CurlTimeout 60]
  Prelude&gt; matchRegex (mkRegexWithOpts "&lt;title&gt;(.*?)&lt;/title&gt;" False True) page
  </code></pre>
  
  <p>in the interpreter, it does precisely what I want it to. When I try to load the same expression, and associated <code>imports</code> from a file, it gives me a type inference error stating that it <code>couldn't match expected type 'IO b' against inferred type 'Maybe [String]'</code>. This tells me I'm missing something small and fundamental, but I can't figure out what. I've tried explicitly casting <code>page</code> to a string, but that's just programming by superstition (and it didn't work in any case). </p>
  
  <p>Any hints?</p>