{-# LANGUAGE LambdaCase #-} {-# LANGUAGE TupleSections #-} module Main where import Data.List (intersperse) import System.Environment (getArgs) import System.Exit (die, exitFailure) import HSVIS.Diagnostic import HSVIS.Parser import HSVIS.Typecheck main :: IO () main = do (source, fname) <- getArgs >>= \case [] -> (,"") <$> getContents [fname] -> (,fname) <$> readFile fname _ -> die "Usage: hs-visinter [filename.hs]" prog <- case parse fname source of (errs, Nothing) -> do sequence_ $ intersperse (putStrLn "") (map (putStrLn . printDiagnostic) errs) exitFailure (errs, Just res) -> do sequence_ $ intersperse (putStrLn "") (map (putStrLn . printDiagnostic) errs) return res print prog let (errs, tprog) = typecheck fname source prog sequence_ $ intersperse (putStrLn "") (map (putStrLn . printDiagnostic) errs) print tprog