[Haskell] ANNOUNCE: knob, a library for memory-backed handles

John Millikin jmillikin at gmail.com
Sun Oct 9 03:50:38 CEST 2011


http://hackage.haskell.org/package/knob

This is a small package which allows you to create memory-backed
handles. I found it as a pattern in a few of my test suites, so I
spent a day or so polishing it up before posting it to the internet.
Feel free to play around with it and tell me about any issues that pop
up, or things you wish it could do.

The interface is very simple; here's a taste:

--------------------------------------------------------------------------
import Data.ByteString (pack)
import Data.Knob
import System.IO

main = do
    -- for this example, we'll start with an empty knob
    knob <- newKnob (pack [])

    -- write to it
    withFileHandle knob "test.txt" WriteMode $ \h -> do
        hPutStrLn h "Hello world!"
    bytes <- Data.Knob.getContents knob
    putStrLn ("Wrote bytes: " ++ show bytes)

    -- read from it
    withFileHandle knob "test.txt" ReadMode $ \h -> do
        line <- hGetLine h
        putStrLn ("Got line: " ++ show line)
--------------------------------------------------------------------------



More information about the Haskell mailing list