> I don't have very much luck with this question in c.l.f. So I'll try it
> here.
>
[..]
> The only change in my example is the use of IO.hugsIsEOF. I looked inot
> IO.hs and isEOF is commented out and the comment says not yet
> implemented so I use this. But now I can't quit the program. I work
> under Linux and STRG+D is normally EOF but it won't stop on typing that
> in. The other point is that if I use a file the file is printed to
> standard output and a lot of garbage too and then runhugs is killed
> because of faults in space reclamation.
As the comment in IO.hs says, hugsIsEOF has the C semantics rather than the Haskell
semantics. From man feof:
The function feof tests the end-of-file indicator for the
stream pointed to by stream, returning non-zero if it is
set.
What this means is that hugsIsEOF doesn't check the file... it checks an indicator,
which is set *only when you attempt to read past the end of file*. This means that to
read a whole file, you read each character until hugsIsEOF says you're done, *then you
throw out the last character you read*.
Of course, the garbage character is unlikely to be an end-of-line char, so you never
stop reading; you'd have to read character by character to find the right place to
stop.
You can see this behaviour more clearly with a simple example:
#!/usr/groups/haskell/ix86_linux/bin/runhugs
import IO
main = do res <- IO.hugsIsEOF
print res
getChar
res' <- IO.hugsIsEOF
print res'
% test.hs < /dev/null
False
?True
%
(where ? is some garbage).
Notice too that if Hugs is taking input from the terminal rather than a file, ^D is
passed through to the app rather than treated as end-of-file; this allows interactive
applications.
I've cc'd this to the hugs-users list in case the developers want to comment.
HTH.
--KW 8-)
--
: Keith Wansbrough, MSc, BSc(Hons) (Auckland) ------------------------:
: PhD Student, Computer Laboratory, University of Cambridge, England. :
: (and recently of the University of Glasgow, Scotland. [><] ) :
: Native of Antipodean Auckland, New Zealand: 174d47' E, 36d55' S. :
: http://www.cl.cam.ac.uk/users/kw217/ mailto:[EMAIL PROTECTED] :
:---------------------------------------------------------------------: