title: Many types of String (ByteString)
body: <p>I wish to compress my application's network traffic. </p>
  
  <p>According to the (latest?) <a href="http://donsbot.wordpress.com/2009/08/29/haskell-popularity-rankings-september-2009/" rel="noreferrer">"Haskell Popularity Rankings"</a>, <a href="http://hackage.haskell.org/packages/archive/zlib/0.5.2.0/doc/html/Codec-Compression-Zlib.html#1" rel="noreferrer">zlib</a> seems to be a pretty popular solution. zlib's interface uses <code>ByteString</code>s:</p>
  
  <pre><code>compress :: ByteString -&gt; ByteString
  decompress :: ByteString -&gt; ByteString
  </code></pre>
  
  <p>I am using regular <code>String</code>s, which are also the data types used by <code>read</code>, <code>show</code>, and <code>Network.Socket</code>:</p>
  
  <pre><code>sendTo :: Socket -&gt; String -&gt; SockAddr -&gt; IO Int
  recvFrom :: Socket -&gt; Int -&gt; IO (String, Int, SockAddr)
  </code></pre>
  
  <p>So to compress my strings, I need some way to convert a <code>String</code> to a <code>ByteString</code> and vice-versa.
  With <a href="http://community.haskell.org/~ndm/hoogle/" rel="noreferrer">hoogle</a>'s help, I found:</p>
  
  <pre><code>Data.ByteString.Char8 pack :: String -&gt; ByteString
  </code></pre>
  
  <p>Trying to use it:</p>
  
  <pre><code>Prelude Codec.Compression.Zlib Data.ByteString.Char8&gt; compress (pack "boo")
  
  &lt;interactive&gt;:1:10:
      Couldn't match expected type `Data.ByteString.Lazy.Internal.ByteString'
             against inferred type `ByteString'
      In the first argument of `compress', namely `(pack "boo")'
      In the expression: compress (pack "boo")
  In the definition of `it': it = compress (pack "boo")
  </code></pre>
  
  <p>Fails, because (?) there are different types of <code>ByteString</code> ?</p>
  
  <p>So basically:</p>
  
  <ul>
  <li>Are there several types of <code>ByteString</code>? What types, and why?</li>
  <li>What's "the" way to convert <code>String</code>s to <code>ByteString</code>s?</li>
  </ul>
  
  <p>Btw, I found that it does work with <code>Data.ByteString.Lazy.Char8</code>'s <code>ByteString</code>, but I'm still intrigued.</p>