packages feed

calculator-0.1.4.0: src/Main.hs

module Main where

--------------------------------------------------------------------------------

import           Calculator.Evaluator.Base     (evaluate)
import           Calculator.Prim.Expr          (Bindings, defBinds)

--------------------------------------------------------------------------------

import           System.Console.Haskeline

--------------------------------------------------------------------------------

type Repl a = InputT IO a

--------------------------------------------------------------------------------

repl :: Bindings -> Repl ()
repl b = do
  input <- getInputLine "calc> "
  case input of
    Nothing  -> return ()
    Just inp -> case evaluate b inp of
                  Left s   -> outputStrLn s >> repl b
                  Right b' -> repl b'

--------------------------------------------------------------------------------

main :: IO ()
main = runInputT defaultSettings (repl defBinds)

--------------------------------------------------------------------------------