diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 12:12:16 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 12:12:16 +0100 |
| commit | ab1b426b917460c09079a21378848ad68242bc9d (patch) | |
| tree | 5311f8ef121f84f36753dab3475735ac402f22d5 /lambda-calcul/haskell | |
| parent | 10feb2dc8ad775a64b6db4d19c76bd6fa38044a8 (diff) | |
| download | lambda-nantes-ab1b426b917460c09079a21378848ad68242bc9d.tar.gz | |
do not display type when piping program
Diffstat (limited to 'lambda-calcul/haskell')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL.hs | 8 | ||||
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/REPLSpec.hs | 18 |
2 files changed, 20 insertions, 6 deletions
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" |
