summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/src/Minilang/IO.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/IO.hs')
-rw-r--r--lambda-calcul/haskell/src/Minilang/IO.hs32
1 files changed, 8 insertions, 24 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/IO.hs b/lambda-calcul/haskell/src/Minilang/IO.hs
index bfcb125..c468316 100644
--- a/lambda-calcul/haskell/src/Minilang/IO.hs
+++ b/lambda-calcul/haskell/src/Minilang/IO.hs
@@ -1,40 +1,24 @@
-{-# LANGUAGE DuplicateRecordFields #-}
-{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-{-# LANGUAGE NamedFieldPuns #-}
-{-# LANGUAGE RecordWildCards #-}
-{-# LANGUAGE TypeSynonymInstances #-}
-{-# OPTIONS_GHC "-fno-warn-orphans" #-}
-
module Minilang.IO where
import qualified Data.ByteString as BS
+import qualified Data.Text as Text
import Data.Text.Encoding
( decodeUtf8With,
encodeUtf8,
)
import Data.Text.Encoding.Error (lenientDecode)
-import Minilang.Lambda.Eval hiding (rho)
-import Minilang.Parser
-import Minilang.Type
-import Prettyprinter
-import Prettyprinter.Render.Text
+import Minilang.Lambda.Eval (eval)
import System.IO (Handle)
--- | Read an `AST` from @hin@ handle, evaluate it and dump the result
+-- | Read a "program" from @hin@ handle, evaluate it and dump the result
-- on @hout@.
runEval :: Handle -> Handle -> IO ()
runEval hin hout = do
- programText <- decodeUtf8With lenientDecode <$> BS.hGetContents hin
- let ast = parseProgram False programText
- ρ = EmptyEnv
- γ = EmptyContext
- (ρ', _) <- loadProgram ast ρ γ
- let val = eval ast ρ'
+ programText <- Text.unpack . decodeUtf8With lenientDecode <$> BS.hGetContents hin
+ let ast = read programText
+ env = mempty
+ result = eval ast env
BS.hPut
hout
- ( encodeUtf8
- ( renderStrict $ layoutPretty defaultLayoutOptions $ pretty val
- )
- <> "\n"
- )
+ (encodeUtf8 (Text.pack (show result) <> "\n"))