summaryrefslogtreecommitdiff
path: root/src/K/Repl.hs
blob: 26f21e1e59784a44a679ada463c223bbad1c18ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module K.Repl where

import Control.Monad.IO.Class
import K.Parsing
import K.Eval
import System.Console.Haskeline

process :: String -> IO ()
process line = do
  let res = parseExpr line
  case res of
    Left err -> print err
    Right ex -> print $ eval ex

main :: IO ()
main = runInputT defaultSettings loop
  where
  loop = do
    minput <- getInputLine "Repl> "
    case minput of
      Nothing -> outputStrLn "Goodbye."
      Just input -> (liftIO $ process input) >> loop