From fc00cff556372e914d3cf15c39700b4ff7c3541c Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Sun, 2 Nov 2025 21:35:19 +0100 Subject: better rendering for type errors and evaluation --- lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs | 9 ++------- lambda-calcul/haskell/src/Minilang/REPL/Run.hs | 3 ++- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'lambda-calcul/haskell/src/Minilang/REPL') diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs b/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs index cbc7988..3583020 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/Haskeline.hs @@ -29,6 +29,7 @@ import System.Console.Haskeline import System.Directory (listDirectory) import Minilang.Lambda.Parser (resugar, pretty) import qualified Minilang.Lambda.Unify as Unify +import Minilang.REPL.Pure (render) -- * Haskeline REPL @@ -44,19 +45,13 @@ instance MonadREPL Haskeline where case i of Nothing -> pure EOF Just (pack -> t) -> pure $ interpret t - output = hoist . outputStrLn . render + output = hoist . outputStrLn . unpack . render prompt = pure () load = fmap (first FileError) . hoist . lift . try . Text.readFile . unpack getEnv = get setEnv = put -render :: Out -> String -render = \case - Msg t -> unpack t - Evaluated term typ -> unpack $ pretty (resugar term) <> " : " <> Unify.pretty typ - other -> show other - completion :: CompletionFunc IO completion = completion' . first reverse diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Run.hs b/lambda-calcul/haskell/src/Minilang/REPL/Run.hs index c90ecde..9c31987 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/Run.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/Run.hs @@ -16,6 +16,7 @@ import Minilang.Lambda.Eval (newEnv) import Minilang.Lambda.Infer (infer, newContext) import Minilang.Lambda.Parser (desugar, parse) import Minilang.REPL.Types +import qualified Minilang.Lambda.Infer as Infer -- | Run a REPL session runREPL :: @@ -41,7 +42,7 @@ handleUserInput txt = do Right expr -> do let term = desugar expr case infer term of - Left typeError -> output (Msg $ pack $ show typeError) + Left typeError -> output (Msg $ Infer.render typeError) Right typ -> do let v = fromDeBruijn $ eval (toDeBruijn term) output (Evaluated v typ) -- cgit v1.3.1