From 1c4a175e00e727ac4987f60503bd7dbaeb3f26ad Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 28 Oct 2025 16:42:28 +0100 Subject: wip: use de Bruijn indices representation provide sample complex terms to evaluate --- lambda-calcul/haskell/src/Minilang/IO.hs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'lambda-calcul/haskell/src/Minilang/IO.hs') diff --git a/lambda-calcul/haskell/src/Minilang/IO.hs b/lambda-calcul/haskell/src/Minilang/IO.hs index 28b6f01..a045647 100644 --- a/lambda-calcul/haskell/src/Minilang/IO.hs +++ b/lambda-calcul/haskell/src/Minilang/IO.hs @@ -7,9 +7,9 @@ import Data.Text.Encoding encodeUtf8, ) import Data.Text.Encoding.Error (lenientDecode) -import Minilang.Lambda.Eval (eval) +import Minilang.Lambda.DeBruijn (eval, toDeBruijn) +import Minilang.Lambda.Parser (desugar, parse, pretty) import System.IO (Handle) -import Minilang.Lambda.Parser (parse, desugar) -- | Read a "program" from @hin@ handle, evaluate it and dump the result -- on @hout@. @@ -17,13 +17,11 @@ runEval :: Handle -> Handle -> IO () runEval hin hout = do programText <- decodeUtf8With lenientDecode <$> BS.hGetContents hin let parsed = parse programText - result = case parsed of - Left err -> show err - Right ast -> - let term = desugar ast - env = mempty - in show $ eval term env - - BS.hPut - hout - (encodeUtf8 (Text.pack result <> "\n")) + case parsed of + Left err -> print err + Right ast -> do + putStrLn $ Text.unpack $ "Evaluating " <> pretty ast + let termy = desugar ast + putStrLn $ "Desugared to " <> show termy + let term = toDeBruijn termy + print $ eval term -- cgit v1.3.1