
I really like the idea of a source and sink class, among other things it would allow things like a sink which spit out a cryptographic hash of everything that went through it discarding the data itself. or one which droped everything to an in-heap list. or even one that split the data into two and sent it to multiple sinks... such a framework would be very useful in real world programming.
It sounds like what we really need is a way to build your own Handles, so you can define these kind of filters. Anyone want to suggest an interface?
also, Haskell really really needs a standard 'Byte' type rather than confusing Char, but I have ranted about this before, I am glad to see other people think the same thing... :)..
Word8 is the standard byte type. You can read bytes from a file like this (untested): readNBytes :: Handle -> Int -> IO [Word8] readNBytes h n = allocaBytes n $ \(p :: Ptr Word8) -> hGetBuf h p n peekArray p n allocaBytes and peekArray are part of the standard FFI libraries, and hGetBuf is originally from GHC's IOExts, but I don't see a reason why it shouldn't be part of the standard IO interface (in fact I've exported it from System.IO in the core libraries). Cheers, Simon
participants (1)
-
Simon Marlow