summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/src/Minilang/REPL.hs
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2026-04-01 16:18:01 +0200
committerArnaud Bailly <arnaud@pankzsoft.com>2026-04-01 16:22:02 +0200
commitf6dde1041a52da4f2e7ccb77eed3c577f9d07798 (patch)
treeee99b8a606b7dcb378744f62245209a7d4d8eda4 /lambda-calcul/haskell/src/Minilang/REPL.hs
parentd820a635afb69c44f736e941bbe094ad6a838073 (diff)
downloadlambda-nantes-f6dde1041a52da4f2e7ccb77eed3c577f9d07798.tar.gz
Remove answers from sent challenges
Also fix integration test
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/REPL.hs')
-rw-r--r--lambda-calcul/haskell/src/Minilang/REPL.hs35
1 files changed, 18 insertions, 17 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL.hs b/lambda-calcul/haskell/src/Minilang/REPL.hs
index 7da2042..35883b9 100644
--- a/lambda-calcul/haskell/src/Minilang/REPL.hs
+++ b/lambda-calcul/haskell/src/Minilang/REPL.hs
@@ -23,34 +23,35 @@ import Minilang.REPL.Pure
import Minilang.REPL.Purer
import Minilang.REPL.Run
import Minilang.REPL.Types
+import System.Console.Haskeline (
+ defaultBehavior,
+ defaultSettings,
+ historyFile,
+ runInputTBehavior,
+ setComplete,
+ )
import System.Environment (lookupEnv)
-import Text.Read (readMaybe)
-import System.Console.Haskeline
- ( defaultBehavior,
- defaultSettings,
- historyFile,
- runInputTBehavior,
- setComplete,
- )
import System.IO (Handle, stderr)
+import Text.Read (readMaybe)
-- | Read the evaluator selection from the @MINILANG_EVAL@ environment variable.
-- Returns 'DeBruijn' when the variable is absent or unrecognised.
evaluatorFromEnv :: IO Evaluator
evaluatorFromEnv =
lookupEnv "MINILANG_EVAL" >>= \case
- Nothing -> pure DeBruijn
+ Nothing -> pure DeBruijn
Just raw -> case readMaybe raw of
Just ev -> pure ev
Nothing -> do
Text.hPutStrLn stderr $
- "Warning: unknown MINILANG_EVAL value " <> Text.pack (show raw)
- <> ", falling back to DeBruijn"
+ "Warning: unknown MINILANG_EVAL value "
+ <> Text.pack (show raw)
+ <> ", falling back to DeBruijn"
pure DeBruijn
-- | Build the initial 'REPLEnv' using the given 'Evaluator'.
replEnvWith :: Evaluator -> REPLEnv
-replEnvWith ev = initialREPL { evaluator = ev }
+replEnvWith ev = initialREPL{evaluator = ev}
-- * Haskeline REPL
@@ -58,8 +59,8 @@ withTerminal :: Evaluator -> IO ()
withTerminal ev =
runInputTBehavior defaultBehavior settings $
evalStateT (runHaskeline runREPL) (replEnvWith ev)
- where
- settings = setComplete completion $ defaultSettings {historyFile = Just "~/.minilang.history"}
+ where
+ settings = setComplete completion $ defaultSettings{historyFile = Just "~/.minilang.history"}
-- * Other REPLs
@@ -79,9 +80,9 @@ withIO ev hin hout = do
Right prog -> case loadProgram ev 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) -- TODO: handle types <> " : " <> Unify.pretty typ
+ where
+ render :: (Term, Maybe Type) -> Text
+ render (term, typ) = pretty (resugar term) <> renderType typ
-- * Pure REPL