diff options
| author | Joel Martin <github@martintribe.org> | 2014-12-23 20:35:48 -0700 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:52 -0600 |
| commit | b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8 (patch) | |
| tree | 4b57f91dcf1df0e079a4251a1cab78fe0188dfb4 /haskell/step0_repl.hs | |
| parent | a816262a057ecc4bd1fd07750d21cab81490f336 (diff) | |
| download | mal-b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8.tar.gz mal-b76aa73bc76a28d7c6bb3c5a43acc9afd9ec42c8.zip | |
Haskell: steps 0-3
Diffstat (limited to 'haskell/step0_repl.hs')
| -rw-r--r-- | haskell/step0_repl.hs | 28 |
1 files changed, 28 insertions, 0 deletions
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 |
