
On Sat, 2009-07-18 at 00:40 +0200, Maciej Piechotka wrote:
I have a data structure of data Monad m => NntpConnection m = NntpConnection { input :: ByteString, output :: ByteString -> m () }
I'd like to create echo structure such that the goes to output is going to (lazy) input. For sure it is possible to use network and IO monad - is is possible to do it purely?
Regards
I come up to with: createEcho :: IO (NntpConnection IO) createEcho = do (r, w) <- runKleisli (Kleisli fdToHandle *** Kleisli fdToHandle) =<< createPipe hSetBuffering r LineBuffering hSetBuffering w LineBuffering c <- hGetContents r return $ NntpConnection c $ hPut w Which have advantage of not involving network stack but is POSIX-specific. Regards