a type theory with equality based on setoids
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

  1. {-# LANGUAGE LambdaCase #-}
  2. module Main where
  3. import Presyntax.Parser
  4. import System.Environment (getArgs)
  5. import Elaboration
  6. import Elaboration.Monad
  7. import Control.Monad.Reader
  8. import Syntax
  9. import Evaluate (elabMetas, zonk, evaluate, quote)
  10. import Syntax.Pretty
  11. import Data.Foldable
  12. import Control.Concurrent
  13. import qualified Data.IntMap.Strict as Map
  14. import Value (Meta(Solved, Unsolved))
  15. main :: IO ()
  16. main = do
  17. [path] <- getArgs
  18. text <- readFile path
  19. x <-
  20. case parseString body text of
  21. Left e -> error (show e)
  22. Right x -> pure x
  23. swapMVar elabMetas mempty
  24. swapMVar elabNext 0
  25. t <- runElab ((,) <$> infer x <*> ask) emptyElabState
  26. case t of
  27. Left e -> traverse_ (putStrLn . showProgError text) e
  28. Right ((x, t), e) -> do
  29. metas <- readMVar elabMetas
  30. for_ (Map.toList metas) $ \case
  31. (n, Unsolved names v) ->
  32. putStrLn $ '?':show n ++ " : " ++ showWithPrec names 0 (quote (Lvl (length names)) (zonk v)) "" ++ " = ? "
  33. (n, Solved v) ->
  34. putStrLn $ '?':show n ++ " = " ++ showTerm 0 (quote (Lvl 0) v) ""
  35. putStrLn . flip id "" $ showTerm 0 x
  36. putStrLn . flip id "" $ showString "Type: " . showTerm 0 (quote (Lvl 0) (zonk t))
  37. let t = quote (Lvl 0) . zonk . evaluate (elabEnv e) $ x
  38. putStrLn $ "Normal form: " ++ showTerm 0 t ""
  39. showProgError :: String -> ProgError -> String
  40. showProgError text (ProgError e sl sc el ec)
  41. | sl == el, sl < length (lines text) =
  42. let code = lines text
  43. line = code !! sl
  44. linum = show sl
  45. caretLine = replicate (length linum) ' ' ++ " | " ++ replicate sc ' ' ++ "^" ++ replicate (ec - sc) '~'
  46. paddedLine = replicate (length linum) ' ' ++ " | "
  47. in unlines [ paddedLine
  48. , linum ++ " | " ++ line
  49. , caretLine
  50. , showElabError e ""
  51. ]
  52. | otherwise = showElabError e ""