[Haskell-cafe] Re: Abstraction leak
apfelmus
apfelmus at quantentunnel.de
Sat Jun 30 04:42:42 EDT 2007
David Roundy wrote:
> On Fri, Jun 29, 2007 at 07:39:28PM +0100, Andrew Coppin wrote:
>> Now I have a problem. It's easy enough to pass the entire data stream
>> through an RLE decoder and feed that to the Huffman table deserialize
>> function, and it will give be back the table. But I now have *no clue*
>> where the table ends in the original stream!
>
> Sounds to me like you want a parsing monad. Generally, when you want
> state, you want a monad, and the field of parsing monads is pretty mature.
> You can either write up a monad of your own, or use one of the existing
> ones (parsec, frisby, read).
Am I missing something or why wouldn't
encode, decode :: String -> String
encode = encodeRLE . encodeHuffman
decode = decodeHuffman . decodeRLE
do the job? This is probably what Andrew intends to do in his Java
version. Note that this not only RLE-encodes the Huffman table but also
(needlessly) the data stream. In case you only want to RLE the table, a
simple Word32 field tracking the size of the Huffman table should be enough.
Regards,
apfelmus
More information about the Haskell-Cafe
mailing list