title: iso-8859-1 special characters error in query result
body: <p>I use the <a href="http://hackage.haskell.org/package/hsparql" rel="nofollow">hsparql</a> library to run a query that returns german text; and thus iso-8859-1 special characters are returned.</p>
  
  <p>I wrote the result of the query to a file using <code>writeFile</code>, but the special characters are not correctly shown. (when viewing the file with emacs)</p>
  
  <p>When I instead write the output of the <code>show</code> function to a file, I get the following output:</p>
  
  <pre><code>["B\195\188ro", ...]
  </code></pre>
  
  <p>Printing out the special character it would mean: <code>["Büro", ....]</code></p>
  
  <p>How can I write special characters correctly to a file? (e.g. "Büro" is correctly show in the file output.)</p>
  
  <p>EDIT:
  I know that show writes the escaped characters. Using writeFile directly doesn't work, I have to check the link given in hammer's answer to find a fix..</p>
  
  <p>EDIT2:
  removed, was the wrong approach.</p>
  
  <p>EDIT3:
  Hammers answer was right on the point. It took only 10 minutes to find the solution, but I needed to be fit and concentrated.</p>
  
  <p>I looked up IO in <a href="http://book.realworldhaskell.org/read/io.html" rel="nofollow">link</a></p>
  
  <p>The solution was (literate haskell):</p>
  
  <pre><code>&gt; writeAllLabels = do
  
  Running my Query (not shown, accesses the RDF TrippleStore):
  &gt;             res &lt;- (selectStr33 (unlines qAllLabels))
  
  &gt;             outh &lt;- openFile "/tmp/haskell_output.txt" WriteMode
  
  this is the important line. If I would write "utf8" her instead of "latin1", I would get the wrong result again, i.e. as before asking the question...
  &gt;             hSetEncoding outh latin1
  
  &gt;             hPutStrLn outh res
  &gt;             hClose outh
  </code></pre>