module Main (main) where

import           AST                (Program (..))
import           Control.Monad      (when)
import           Eval               (reduce)
import           Parse
import           System.Environment (getArgs)
import           TypeCheck          (inferProgram)

main :: IO ()
main = do
  args <- getArgs
  s <- getContents
  let p@(Program (_, term)) = parse s
  let (_, tRes) = inferProgram p

  when ("-i" `elem` args) $ putStrLn s
  when ("-p" `elem` args) $ print p
  when ("-t" `elem` args) $ case tRes of
          Left err -> error err
          Right t  -> when ("-t" `elem` args) $ print t

  when ("-e" `elem` args) $ case tRes of
          Left err -> error err
          Right _  -> print $ reduce term

