I will not try to write the entire Haskell program that you are asking for, but here is a very short example showing only the bit that you claim to be stuck at the moment: do something after each keystroke. We wonβt do anything interesting (just jot down a number and print it out), but it will show how to complete this small task, and you can probably start hacking from there.
The only thing you really need to know is that you don't seem to be able to disable input line buffering.
import System.IO loop n = do c <- getChar print n -- do whatever recalculation you need to do here, using -- n (which can be more complicated than an Integer, as -- it is here, of course) and c (which is a Char -- representing the key the user whacked) -- our recalculation is just to increase n by one loop (n+1) main = do hSetBuffering stdin NoBuffering -- do this once before anything else loop 0
Daniel Wagner
source share