On Mon, Apr 1, 2013 at 11:52 AM, Lyndon Maydwell <maydwell@gmail.com> wrote:
The untilexit definition is pretty straightforward. You can see that the the function operates on a string. There are two cases where nothing is returned: "" and "exit" ++ rest.


Ok, that's clear. What I don't understand is why does it stop interact? It returns the same thing if the input is empty or if it starts with "exit". Why doesn't it stop interact when the input line is empty?
 
In order to display a prompt before each input you will need to actually display a prompt /after/ each line, and an additional prompt before you start processing input.

I was trying to do that but I was doing it wrong. Anyway this is the result which works as expected now, although I don't really understand why it stops at 'exit'

import System.IO

prompt = ">> "

main :: IO ()
main = do
    hSetBuffering stdout NoBuffering
    putStr prompt
    interact $ display . map reverse . lines . untilexit

display =  concat . map appendPrompt
    where appendPrompt line = line ++ "\n" ++ prompt

untilexit :: String -> String
untilexit ('e':'x':'i':'t':_)  = []
untilexit (c:t)               = c : untilexit t
untilexit []                  = []