On Mon, May 5, 2008 at 1:45 PM, Andrew Coppin <
andrewcoppin@btinternet.com> wrote:
Neil Mitchell wrote:
hGetContents might be a different way to write a similar thing:
read_args h = do
src <- hGetContents h
let (has,rest) = span ("#" `isPrefixOf`) $ lines src
return (map tail has)
Of course, depending on exactly the kind of IO control you need to do,
it may not work.
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.)
Another minor observation: if the partial pattern in the original code was intentional, then this is not exactly the same.
what about
read_args' :: [String] -> ([String],[String])
read_args' src = span ("#" `isPrefixOf`) $ lines src
and then using
s <- hGetContents
let (arg, rest) = read_args' $ lines s
...
So that you can get both the result and the remaining list of lines, in case you need them. Again, this does not exactly stop where there is a "." on a single line; it stops as soon as it gets a line without a '#'.
Abhay