Deleting items in stdin with haskell

haskell, input, io

Solution

Compile the program and then run the compiled executable. This will give the correct behavior for the Delete key. For some reason interpreting the program screws up the use of Delete.

To compile the program, just invoke `ghc` like this:

$ ghc -O2 myProgram.hs

This will generate a `myProgram` executable that you can run from the command line:

$ ./myProgram

That will then give the correct behavior for Delete.

Problem

I have a bit of code in my haskell program like so: ``` evaluate :: String -> IO () evaluate = ... repl = forever $ do putStr "> " >> hFlush stdout getLine >>= evaluate ``` Problem is, when I press the delete key (backspace on windows), instead of deleting a character from the buffer, I get a `^?` character instead. What's the canonical way of getting delete to delete a character when reading from stdin? Similarly, I'd like to be able to get the arrow keys to move a cursor around, etc.

Original source