From fa9a9758e0d15abe670fbbfd8efa1fce013b1414 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Tue, 23 Dec 2014 22:37:43 -0700 Subject: Haskell: steps 4-6. Line editing. Simpler fn calls. --- haskell/step0_repl.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'haskell/step0_repl.hs') diff --git a/haskell/step0_repl.hs b/haskell/step0_repl.hs index d944263..ab83602 100644 --- a/haskell/step0_repl.hs +++ b/haskell/step0_repl.hs @@ -1,6 +1,7 @@ -import System.IO (hGetLine, hFlush, hIsEOF, stdin, stdout) import Control.Monad +import Readline (readline, load_history) + -- read mal_read str = str @@ -14,15 +15,14 @@ mal_print exp = exp rep line = mal_print $ eval (mal_read line) "" repl_loop = do - putStr "user> " - hFlush stdout - ineof <- hIsEOF stdin - when (not ineof) $ do - line <- hGetLine stdin - if null line - then repl_loop - else do - putStrLn $ rep line - repl_loop + line <- readline "user> " + case line of + Nothing -> return () + Just "" -> repl_loop + Just str -> do + putStrLn $ rep str + repl_loop -main = repl_loop +main = do + load_history + repl_loop -- cgit v1.2.3