title: MapReduce in Haskell
body: <p>I'm trying to implement the <code>MapReduce</code> function. I have to do it without any parallelism, I have this so far:</p>
  
  <pre><code>import Data.Map
  import Data.Char
  
  map_ list = toList $ fromListWith (+) [(x, 1) | x &lt;- list]
  
  main_ = map_ $ getWords "test.txt" --getting error here
  
  prettyprint [(x, y):xs] =  x ++ " : " ++ y -- trying to print out list
  
  -- Loads words from a text file into a list.
  getWords :: FilePath -&gt; IO [String]
  getWords path = do contents &lt;- readFile path
                 return ([map toLower x | x &lt;- words contents]) --- Ambiguous occurrence `map'
  </code></pre>
  
  <p>The main task is to use <code>MapReduce</code> to get a list of words from a file and the frequency of every new word.</p>
  
  <p><strong>I don't understand how the reduce works in this case. I just know that I am mapping a list to a function that calculates the frequency of the words. How can it be reduced?</strong></p>