Streams is an I/O library designed to eventually replace the current I/O facilities based on using Handles. The main advantage is its strong modular design using typeclasses. It consists of small independent modules, each implementing one type of stream (file, memory buffer, pipe, etc.) or one part of common stream functionality (buffering, char encoding, locking, etc.).
3rd-party librarie can easily add new stream types and new common functionality. Other benefits of the new library include support for streams functioning in any monad, Hugs and GHC compatibility, high speed, and an easy migration path from the existing I/O library. It is heavily based on the HVIO module written by John Goerzen.
The key concept of the lib is the Stream class, whose interface mimics familiar interface for Handles, just with "h" replaced with "v" in function names:
class (Monad m) => Stream m h where
vPutStrLn :: h -> String -> m ()
vGetContents :: h -> m String
vIsEOF :: h -> m Bool
vClose :: h -> m ()
This means that you already know how to use any stream! The Stream interface currently has 8 implementations: a Handle itself, raw files, pipes, memory buffers and string buffers. Future plans include support for memory-mapped files, sockets, circular memory buffers for interprocess communication and UArray-based streams.
By themselves, these Stream implementations are rather simple.
Basically, to implement new Stream type, it's enough to provide vPutBuf/vGetBuf operations, or even vGetChar/vPutChar. The latter way, although inefficient, allows us to implement streams that can work in any monad. StringReader and StringBuffer streams use this to provide string-based Stream class implementations both for IO and ST monads. Yes, you can use the full power of Stream operations inside the ST monad!