DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / haskell / step0_repl.hs
1 import System.IO (hFlush, stdout)
2
3 import Readline (addHistory, readline, load_history)
4
5 type MalVal = String
6
7 -- read
8
9 mal_read :: String -> MalVal
10 mal_read = id
11
12 -- eval
13
14 eval :: MalVal -> MalVal
15 eval = id
16
17 -- print
18
19 mal_print :: MalVal -> String
20 mal_print = id
21
22 -- repl
23
24 rep :: String -> String
25 rep = mal_print . eval . mal_read
26
27 repl_loop :: IO ()
28 repl_loop = do
29 line <- readline "user> "
30 case line of
31 Nothing -> return ()
32 Just "" -> repl_loop
33 Just str -> do
34 addHistory str
35 putStrLn $ rep str
36 hFlush stdout
37 repl_loop
38
39 main :: IO ()
40 main = do
41 load_history
42
43 repl_loop