Here goes nothing..

Sigbjorn Finne sof@galois.com
Thu, 30 May 2002 09:43:50 -0700


"C.Reinke" <C.Reinke@ukc.ac.uk> writes:
>
> > Thanks for reporting this; now fixed.
> > 
> > --sigbjorn
> 
> Thanks for fixing;
> as usual, I'm impressed by this efficiency!-)
> 

fyi, the fix implements what the Report prescribes, but I
don't agree with it -- getLine ought not raise an exception
on EOF when having read in a partial line. As is, you will lose
input if it isn't terminated by a newline. Not too cool.

> Btw, is there a way to indicate end-of-input in Hugs?
> 
> In typical shells, that would be CTRL-D, and makes things
> like the "cat >script" work at the prompt (and it doesn't
> end the shell if there is a nested process waiting for input).
> 

Yes, you can (by being EOT-savvy):

getLine :: IO [Char]
getLine = do
   ch <- getChar
   if ch == '\n' || ch == '\EOT'
    then return ""
    else do
       ls <- getLine
       return (ch:ls)

Whether or not this should be done by Prelude-provided functions
like 'getLine', 'interact' and 'getContents' is worth giving some thought.
There is a risk of introducing breakage though, as binary data read
in via stdin will then be interpreted in unintended ways.

--sigbjorn