Unsure about 'IO'

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Wed, 6 Feb 2002 16:33:18 +0000


The problem here is that, within the `while' you are calling `isEOF'
before printing the prompt.  IsEOF cannot report False until you
actually type the first character!  If you type nothing, then it the
EOF condition could indeed be true, so no more actions can happen until
the condition is falsified.

>   processline = do putStr "prompt: " 
>                    line <- getLine
>                    putStrLn ("Read: " ++ line)
> 
>   while :: Monad m => m Bool -> m a -> m ()
>   while t s = do b <- t
>                  if(b)
>                    then do { s; while t s; return () }
>                    else do { return () }
> 
>   main = do hSetBuffering stdout NoBuffering
>             putStrLn "Single call:"
>             processline
>             putStrLn "Call from 'while' construct:"
>             while (notM isEOF) (processline)

Regards,
    Malcolm