[Haskell-beginners] Re: Talking betwean the parsers.

Maciej Piechotka uzytkownik2 at gmail.com
Fri Jul 17 19:05:15 EDT 2009


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20090717/f6055905/attachment.bin


More information about the Beginners mailing list