diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 09:15:46 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 09:15:46 +0100 |
| commit | ae59f17cb3d58de7afca7f441d8bcf9a718e024c (patch) | |
| tree | e1ca429a9a5468f6e69b998eef91bb16727054c7 /lambda-calcul/haskell/src/Minilang/REPL/Run.hs | |
| parent | 62651f13e08304d8fa6395fde7352984f48adb46 (diff) | |
| download | lambda-nantes-ae59f17cb3d58de7afca7f441d8bcf9a718e024c.tar.gz | |
handle defitions in untyped language
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/REPL/Run.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL/Run.hs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Run.hs b/lambda-calcul/haskell/src/Minilang/REPL/Run.hs index bc552cb..a98ff41 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/Run.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/Run.hs @@ -7,13 +7,14 @@ module Minilang.REPL.Run where import Control.Monad.Catch +import Data.Bifunctor (second) import Data.Text hiding (replicate) import Minilang.Lambda (loadProgram) -import Minilang.Lambda.DeBruijn (eval, fromDeBruijn, toDeBruijn) +import Minilang.Lambda.DeBruijn (eval, eval', fromDeBruijn, toDeBruijn) import Minilang.Lambda.Eval (newEnv) import Minilang.Lambda.Infer (infer, newContext) import qualified Minilang.Lambda.Infer as Infer -import Minilang.Lambda.Parser (desugar, parse, resugar) +import Minilang.Lambda.Parser (AST (..), desugar, parse, resugar) import Minilang.Lambda.Unify (Type (TyVar)) import Minilang.REPL.Types @@ -35,12 +36,25 @@ handleUserInput :: Text -> m () handleUserInput txt = do - REPLEnv {language} <- getEnv + repl@REPLEnv {language, env} <- getEnv case parse txt of Left err -> output (Msg $ pack $ show err) + Right (Def ident body) -> do + let term = desugar body + case language of + Typed -> + case infer term of + Left typeError -> output (Msg $ Infer.render typeError) + Right typ -> do + setEnv $ repl {env = (ident, term) : env} + output (Defined ident typ) + Untyped -> do + setEnv $ repl {env = (ident, term) : env} + output (Defined ident (TyVar "<?>")) Right expr -> do let term = desugar expr - v = fromDeBruijn $ eval (toDeBruijn term) + env' = second toDeBruijn <$> env + v = fromDeBruijn $ eval' env' (toDeBruijn term) ast = resugar v case language of Typed -> |
