aboutsummaryrefslogtreecommitdiff
path: root/haskell/step0_repl.hs
blob: 639640057b8c78564b34e9104692f5c2956dd85f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import System.IO (hFlush, stdout)

import Readline (readline, load_history)

-- 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
    line <- readline "user> "
    case line of
        Nothing -> return ()
        Just "" -> repl_loop
        Just str -> do
            putStrLn $ rep str
            repl_loop

main = do
    load_history
    repl_loop