[Haskell-cafe] A common pattern
Andrew Coppin
andrewcoppin at btinternet.com
Mon May 5 06:29:04 EDT 2008
Abhay Parvate wrote:
> Hi Andrew,
>
> I don't know whether it's intentional, but the patterns for "case line
> of" are not exaustive. Are you sure you do not expect anything else
> apart from a single "." or a line starting with '#'?
It's reading a wire protocol, so if you hit anything else there's been a
protocol error. Arguably I should probably catch this case and report it
gracefully. But really, there isn't much you could usefully do in this
situation.
> Please correct me if I am wrong; but the rest of the contents from the
> handle h will be unavailable after the evaluation of this function: it
> goes into a semi-closed state. (Correctly so: 'src' is supposed to
> have the entire contents obtained from h if needed.)
>
Quite so. If I was going with this approach, I'd have to call
hGetContents and then parse the entire stream and act on it.
For my current application, which is basically a server that receives
requests and then replies to them, I *think* you could possibly do that.
If, however, there were to be some command that said "hey, disregard
everything I just said, and switch to this new parsing mode..." then I'd
have a problem implementing that this way.
More information about the Haskell-Cafe
mailing list