アプリケーションのネットワーク トラフィックを圧縮したいと考えています。
(最新の?) "Haskell Popularity Rankings"によると、zlibはかなり人気のあるソリューションのようです。zlib のインターフェースはByteStrings を使用します:
compress :: ByteString -> ByteString
decompress :: ByteString -> ByteString
これは、 、、および でString使用されるデータ型でもあります。readshowNetwork.Socket
sendTo :: Socket -> String -> SockAddr -> IO Int
recvFrom :: Socket -> Int -> IO (String, Int, SockAddr)
したがって、文字列を圧縮するには、aStringを a に、ByteStringまたはその逆に変換する方法が必要です。hoogleの助けを借りて、次のことがわかりました。
Data.ByteString.Char8 pack :: String -> ByteString
それを使用しようとしています:
Prelude Codec.Compression.Zlib Data.ByteString.Char8> compress (pack "boo")
<interactive>: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")
(?) にはさまざまな種類のByteString?があるため、失敗します。
だから基本的に:
- にはいくつかの種類があり
ByteStringますか? どのような種類で、その理由は? Strings をsに変換する「the」方法は何ByteStringですか?
ところで、私はそれがData.ByteString.Lazy.Char8'sByteStringで動作することを発見しましたが、私はまだ興味をそそられています。