From b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Tue, 23 Dec 2014 20:35:48 -0700 Subject: Haskell: steps 0-3 --- haskell/step0_repl.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 haskell/step0_repl.hs (limited to 'haskell/step0_repl.hs') diff --git a/haskell/step0_repl.hs b/haskell/step0_repl.hs new file mode 100644 index 0000000..d944263 --- /dev/null +++ b/haskell/step0_repl.hs @@ -0,0 +1,28 @@ +import System.IO (hGetLine, hFlush, hIsEOF, stdin, stdout) +import Control.Monad + +-- read +mal_read str = str + +-- eval +eval ast env = ast + +-- print +mal_print exp = exp + +-- repl +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 + +main = repl_loop -- cgit v1.2.3