diff options
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/REPL/Pure.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL/Pure.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs index 23c45e1..91e71b9 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs @@ -8,6 +8,8 @@ import Control.Monad.Catch import Control.Monad.Catch.Pure (CatchT (..)) import Control.Monad.State import Data.Text hiding (replicate) +import Minilang.Lambda.Parser (pretty, resugar) +import qualified Minilang.Lambda.Unify as Type import Minilang.REPL.Types data PureEnv = PureEnv @@ -21,20 +23,25 @@ newtype PureREPL a = PureREPL {runPure :: CatchT (State PureEnv) a} instance MonadREPL PureREPL where input = do - ins <- inputText <$> get + ins <- gets inputText case ins of [] -> pure EOF (t : ts) -> modify (\e -> e {inputText = ts}) >> pure (interpret t) output t = modify $ \e -> e {outputText = render t : outputText e} + prompt = pure () - getEnv = get >>= pure . pureREPL + + getEnv = gets pureREPL + setEnv e' = modify $ \e -> e {pureREPL = e'} + load f = pure $ Left $ REPLError $ "cannot load file " <> f <> " in Pure interpreter" render :: Out -> Text render = \case Msg t -> t + Evaluated term typ -> pretty (resugar term) <> " : " <> Type.pretty typ Bye -> "Bye!" other -> pack (show other) |
