
We've been working on bulding an interpreter in haskell and we seem to have encountered a problem. At the end of the email I've pasted a minimal version of the program, that shows the error.
The problem is that we 'putStr' a prompt onto (unbuffered) stdout and then read a line, process it and 'print' output, all very basic.
This is done in the function 'processline' and works fine is this function is used directly from 'main', however, if used from within the 'while' construct it fails. In the 'while' context it appears that the 'getLine' is executed before the 'putStr' is (or perhaps stdout is not as 'unbuffered' as we expect ?).
In your example it is the 'isEOF' that is waiting for input. The I/O system can't determine whether the end of the input has been reached yet without waiting for the user to type something: the user might type ^D which would indicate EOF, or they might type some characters. This is arguably wrong, although it does seem to follow the Haskell Library Report (section 11.4.1). Strictly speaking, it would be wrong not to block in isEOF because we might be at the end of file and not know it yet. You can use hReady to determine whether isEOF will block (although interestingly the report says that hReady can fail with an EOF error; GHC won't do this in practice). Cheers, Simon
participants (1)
-
Simon Marlow