[Haskell-cafe] Abstraction leak
Andrew Coppin
andrewcoppin at btinternet.com
Fri Jun 29 14:55:57 EDT 2007
Miles Sabin wrote:
> Andrew Coppin wrote,
>
>> If this was Java, you would write all these compression and
>> decompression stages as stream wrappers. So you wrap the raw input
>> stream with an RLE decoder, have the function read the Huffman table,
>> and then take off the RLE decoder and process the rest of the stream.
>>
>
> Except that if the RLE decoding stream wrapper contains any internal
> buffering, then stripping it off would very likely result in data loss.
>
...which is why you design your RLE decoding wrapper to not buffer
anything. ;-)
You'd have more fun with bit-oriented things. But then, you'd design an
object representing a stream of bits instead of a stream of
bytes/characters/whatever, and it'd be fine.
> What you actually have to do is have the RLE decoding stream wrapper
> build and return you a stream wrapper which delivers the remainder of
> the stream.
>
> Which I think shows that the abstraction isn't leaky ... where "the
> remainder" starts is very much dependent on the precise encoding of the
> prefix of the stream.
>
It's just that at present, both the Huffman table load and save
functions have no idea that they're operating through an RLE layer.
Unfortunately, to be able to get the rest of the data, I have to expose
to those functions the fact that there's this extra layer happening.
(And then what if I want to use something else instead of RLE? What if I
want to put *several* layers in? It all gets very messy...)
More information about the Haskell-Cafe
mailing list