title: How does GHC/Haskell decide what character encoding it's going to decode/encode from/to?
body: <p>It seems that GHC is at least inconsistent in the character encoding it decides to decode from.</p>
  
  <p>Consider a file, <code>omatase-shimashita.txt</code>, with the following content, encoded in UTF-8: お待たせしました</p>
  
  <p><code>readFile</code> seems to read this in properly...</p>
  
  <pre><code>Prelude&gt; content &lt;- readFile "/home/chris/Desktop/omatase-shimashita.txt"
  Prelude&gt; length content
  8
  Prelude&gt; putStrLn content
  お待たせしました
  </code></pre>
  
  <p>However, if I write a simple "echo" server, it does not decode with a default of UTF-8.  Consider the following code that handles an incoming client:</p>
  
  <pre><code>handleClient handle = do
    line &lt;- hGetLine handle
    putStrLn $ "Read following line: " ++ toString line
    handleClient handle
  </code></pre>
  
  <p>And the relevant client code, explicitly sending UTF-8:</p>
  
  <pre><code>Data.ByteString.hPutStrLn handle $ Codec.Binary.UTF8.Generic.fromString "お待たせしました"
  </code></pre>
  
  <p>Is this not inconsistent behavior?  Is there any method to this madness?  I am planning to rewrite my application(s) to explicitly use <code>ByteString</code> objects and explicitly encode and decode using <code>Codec.Binary.UTF8</code>, but it would be good to know what's going on here anyway...  :o/</p>
  
  <p>UPDATE: I am running on Ubuntu Linux, version 10.10, with a locale of en_US.UTF-8...</p>
  
  <pre><code>$ cat /etc/default/locale 
  LANG="en_US.UTF-8"
  $ echo $LANG 
  en_US.UTF-8
  </code></pre>