title: Lazily evaluate monadic functions in Haskell
body: <p>I can't seem to figure out a workaround for this issue i'm having.</p>
  
  <p>I have something like this:</p>
  
  <pre><code>  getFilePathForDay :: Day -&gt; IO (Maybe FilePath)
  
    getFilePathForDays date days = do
        files &lt;- mapM getFilePathForDay $ iterate (addDays 1) date
        return . take days . catMaybes $ files
  </code></pre>
  
  <p>I am trying to get x amount of valid file paths where x is the number of days I want, but the above code just runs forever. I have ran into this problem before with monads and I was wondering if there is a workaround available for this issue I am having.</p>
  
  <p>Thanks! </p>