[Haskell-cafe] Parsec and network data

Donn Cave donn at avvanta.com
Fri Aug 29 18:49:09 EDT 2008

Quoth brian <brianchina60221 at gmail.com>:
| On Fri, Aug 29, 2008 at 11:15 AM, Donn Cave <donn at avvanta.com> wrote:
|> Quoth brian <brianchina60221 at gmail.com>:
|> | I want to use Parsec to parse NNTP data coming to me from a handle I
|> | get from connectTo.
|> I would implement the network service
|> input data stream myself, with timeouts
| Could you explain a little about how this would look?
| If it's reading characters trying to make a String we want to call a
| 'line', isn't that what the parser is supposed to be doing? If you
| were parsing /etc/passwd, would you read each line yourself and give
| each one to Parsec?

You bet, given that passwd is a simple line record file and I'm reasonably
confident that hGetLine will do what I want for a disk file (or more or
less so, anyway, since while I don't want end of file to raise an exception,
I'm aware of work-arounds for this.)  On the other hand, for the very same
reason, I wouldn't worry too much about letting a parse function read the
data -- from a disk file.

With a network client, though, the value of those buffered I/O routines
isn't so obvious to me.  While it can be a convenient metaphor in some
common circumstances, a socket is not a file and the notion easily becomes
more trouble than it's worth.

I wouldn't read byte-by-byte, but rather read available data into my own

	Donn Cave, donn at avvanta.com

More information about the Haskell-Cafe mailing list