[Haskell-cafe] Fun with ByteStrings [was: A very edgy language]

Stefan O'Rear stefanor at cox.net
Sun Jul 8 11:27:06 EDT 2007

On Sun, Jul 08, 2007 at 04:16:46PM +0100, Andrew Coppin wrote:
> Malte Milatz wrote:
>> Stefan O'Rear:
>>> [Char] is a linked list of pointers to heap-allocated fullword integers, 
>>> 20 (40) bytes per character (assuming non-latin1).
>> Hey, I love ByteStrings!  ;-)
> If only there were a way to write functions that transparently work on both 
> [x] and ByteString...
> (Well, I mean, there *is* - if you want to write *lots* of code by hand 
> yourself...)
> Anyone have any comments on how ByteString is different from, say, UArray 
> Word8?

1. ByteString uses pinned memory, so you can safely pass ByteStrings to
   C code (as char*) without worrying about the strings moving.

2. ByteString uses foreignptrs, which mean that you can construct
   bytestrings from any block of memory, and you can associate arbitrary
   actions (free(), nothing, something fancier, ...) with the ByteString
   becoming unreferenced.

3. ByteString uses explicit offset and length fields, allowing a O(1)
   tail operation (very important for functional-style code)

4. Lazy bytestrings are completely different - look elsewhere in this


More information about the Haskell-Cafe mailing list