title: Expressing a sequence of scripted Python string replacement in Haskell
body: <p>I often use Python to replace various types of characters in text, using scripts that look like this:</p>
  
  <pre><code>#!/usr/bin/env python                                                                                                                                                                                                                                                         
  # coding=UTF-8
  
  import sys
  
  for file in sys.argv[1:]:                                                                                                                                                                                                                                                     
      f = open(file)                                                                                                                                                                                                                                                            
      fs = f.read()
      r1 = fs.replace('\n',' ')
      r2 = r1.replace('\r',' ')                                                                                                                                                                                                                                                   
      r3 = r2.replace('. ','.\n\n')                                                                                                                                                                                                                                                   
      r4 = r3.replace('é','e')
      r5 = r4.replace('\xc2',' ')
      r6 = r5.replace('\xa0',' ')
      r7 = r6.replace(' ',' ')
      r8 = r7.replace(' ',' ')
      r9 = r8.replace('\n ','\n')
      f.close()                                                                                                                                                                                                                                                                 
      print r8
  </code></pre>
  
  <p>But I am learning Haskell now, because I am sick of Python. </p>
  
  <p>My best try at doing that in Haskell is</p>
  
  <pre><code>#!/usr/bin/runhaskell 
  
  import System.IO
  
  main :: IO ()
  main = do 
         inh &lt;- getArgs &gt;&gt;= withFileLines
         outh &lt;- -- ??
         mainloop inh outh
         hClose inh
         hClose outh
  
  replacements :: String -&gt; String
  replacements = unwords $ map -- hmm....
  </code></pre>
  
  <p>...and, I have no idea where to go from there.</p>