title: Haskell map does not iterate over the whole list
body: <p>I'm trying to learn the basics of Haskell while developing a filter for Pandoc to recursively include additional markdown files.</p>
  
  <p>Based on the scripting guide I was able to create a somewhat working filter. This looks for CodeBlocks with the <code>include</code> class and tries to include the ASTs of the referenced files.</p>
  
  <pre><code>```include
  section-1.md
  section-2.md
  #pleasedontincludeme.md
  ```
  </code></pre>
  
  <p>The whole filter and the input sources could be found in the following repository: <a href="https://github.com/steindani/pandoc-include" rel="nofollow">steindani/pandoc-include</a> (or see below)</p>
  
  <p>One could run pandoc with the filter and see the output in markdown format using the following command: <code>pandoc -t json input.md | runhaskell IncludeFilter.hs | pandoc --from json --to markdown</code></p>
  
  <p>I've noticed that the <code>map</code> function (<a href="https://github.com/steindani/pandoc-include/blob/8329e6e348ec8b5b5d15c5280911e947b62063c6/IncludeFilter.hs#L38" rel="nofollow">at line 38</a>) — although gets the list of files to include — only calls the function for the first element. And this is not the only strange behavior. The included file could also have an include block that is processed and the referenced file is included; but it won't go deeper, the include blocks of the last file are ignored.</p>
  
  <p>Why does not the map function iterate over the whole list? Why does it stop after 2 levels of hierarchy?</p>
  
  <p><em>Please note that I'm just starting to learn Haskell, I'm sure I made mistakes, but I'm happy to learn.</em></p>
  
  <p>Thank you</p>
  
  <p>Full source code:</p>
  
  <pre><code>module Text.Pandoc.Include where
  
  import Control.Monad
  import Data.List.Split
  
  import Text.Pandoc.JSON
  import Text.Pandoc
  import Text.Pandoc.Error
  
  stripPandoc :: Either PandocError Pandoc -&gt; [Block]
  stripPandoc p =
    case p of
      Left _ -&gt; [Null]
      Right (Pandoc _ blocks) -&gt; blocks
  
  ioReadMarkdown :: String -&gt; IO(Either PandocError Pandoc)
  ioReadMarkdown content = return (readMarkdown def content)
  
  getContent :: String -&gt; IO [Block]
  getContent file = do
    c &lt;- readFile file
    p &lt;- ioReadMarkdown c
    return (stripPandoc p)
  
  doInclude :: Block -&gt; IO [Block]
  doInclude cb@(CodeBlock (_, classes, _) list) =
    if "include" `elem` classes
      then do
        files &lt;- return $ wordsBy (=='\n') list
        contents &lt;- return $ map getContent files
        result &lt;- return $ msum contents
        result
      else
          return [cb]
  doInclude x = return [x]
  
  main :: IO ()
  main = toJSONFilter doInclude
  </code></pre>