diff options
| author | Joel Martin <github@martintribe.org> | 2014-12-23 22:37:43 -0700 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:52 -0600 |
| commit | fa9a9758e0d15abe670fbbfd8efa1fce013b1414 (patch) | |
| tree | 7ee5dceceaa79cf0269ae74d10aa297504c69da3 /haskell/step0_repl.hs | |
| parent | b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8 (diff) | |
| download | mal-fa9a9758e0d15abe670fbbfd8efa1fce013b1414.tar.gz mal-fa9a9758e0d15abe670fbbfd8efa1fce013b1414.zip | |
Haskell: steps 4-6. Line editing. Simpler fn calls.
Diffstat (limited to 'haskell/step0_repl.hs')
| -rw-r--r-- | haskell/step0_repl.hs | 24 |
1 files changed, 12 insertions, 12 deletions
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 |
