From ab1b426b917460c09079a21378848ad68242bc9d Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 5 Nov 2025 12:12:16 +0100 Subject: do not display type when piping program --- lambda-calcul/haskell/src/Minilang/REPL.hs | 8 ++++---- lambda-calcul/haskell/test/Minilang/REPLSpec.hs | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'lambda-calcul/haskell') diff --git a/lambda-calcul/haskell/src/Minilang/REPL.hs b/lambda-calcul/haskell/src/Minilang/REPL.hs index ae25822..a8d3c77 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL.hs @@ -52,15 +52,15 @@ withHandles hin hout = -- | Simple IO REPL, used to evaluate programs from stdin or file loading withIO :: Handle -> Handle -> IO () withIO hin hout = do - input <- parseProgram <$> Text.hGetContents hin - case input of + programText <- parseProgram <$> Text.hGetContents hin + case programText of Left err -> Text.hPutStrLn hout (Text.pack (show err)) - Right inputs -> case loadProgram Untyped newEnv newContext inputs of + Right prog -> case loadProgram Untyped newEnv newContext prog of Right (results, _, _) -> mapM_ (Text.hPutStrLn hout . render) results Left err -> Text.hPutStrLn hout (Text.pack $ show err) where render :: (Term, Type) -> Text - render (term, typ) = pretty (resugar term) <> " : " <> Unify.pretty typ + render (term, _typ) = pretty (resugar term) -- TODO: handle types <> " : " <> Unify.pretty typ -- * Pure REPL diff --git a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs index 851706c..74f6c29 100644 --- a/lambda-calcul/haskell/test/Minilang/REPLSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/REPLSpec.hs @@ -92,8 +92,12 @@ spec = parallel $ it "can load 'bool-prog.lisp'" $ do boolProg <- readFile "bool-prog.lisp" - let PurerEnv{outputs} = runProgram (loadProgramInEnv boolProg) - outputs `shouldBe` [] + let PurerEnv {outputs} = runProgram (loadProgramInEnv boolProg) + outputs + `shouldBe` [ Evaluated (Abs ["f", "t"] (Sym "t")) (Lam "f" (Lam "t" (Var "t"))) (TyVar ""), + Evaluated (Abs ["f", "t"] (Sym "f")) (Lam "f" (Lam "t" (Var "f"))) (TyVar ""), + Evaluated (Abs ["f", "t"] (Sym "f")) (Lam "f" (Lam "t" (Var "f"))) (TyVar "") + ] it "can load 'bool.lisp'" $ do boolProg <- readFile "bool.lisp" @@ -105,6 +109,16 @@ spec = parallel $ (TyVar "") ] + it "can load 'fac.lisp'" $ do + boolProg <- readFile "fac.lisp" + let PurerEnv {outputs} = runProgram (loadProgramInEnv boolProg) + outputs + `shouldBe` [ Evaluated + (Abs ["f", "t"] (Sym "t")) + (Lam "f" (Lam "t" (Var "t"))) + (TyVar "") + ] + around withTempFile $ it "evaluates single MiniLang term read from IO" $ \fileName -> do let outputFileName = fileName <> ".out" -- cgit v1.3.1