diff options
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/IO.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/IO.hs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/IO.hs b/lambda-calcul/haskell/src/Minilang/IO.hs index c468316..28b6f01 100644 --- a/lambda-calcul/haskell/src/Minilang/IO.hs +++ b/lambda-calcul/haskell/src/Minilang/IO.hs @@ -9,16 +9,21 @@ import Data.Text.Encoding import Data.Text.Encoding.Error (lenientDecode) import Minilang.Lambda.Eval (eval) import System.IO (Handle) +import Minilang.Lambda.Parser (parse, desugar) -- | Read a "program" from @hin@ handle, evaluate it and dump the result -- on @hout@. runEval :: Handle -> Handle -> IO () runEval hin hout = do - programText <- Text.unpack . decodeUtf8With lenientDecode <$> BS.hGetContents hin - let ast = read programText - env = mempty - result = eval ast env + 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 (show result) <> "\n")) + (encodeUtf8 (Text.pack result <> "\n")) |
