diff options
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/REPL/Pure.hs')
| -rw-r--r-- | lambda-calcul/haskell/src/Minilang/REPL/Pure.hs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs index 8250152..d9dbbbe 100644 --- a/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs +++ b/lambda-calcul/haskell/src/Minilang/REPL/Pure.hs @@ -13,9 +13,9 @@ import qualified Minilang.Lambda.Unify as Type import Minilang.REPL.Types data PureEnv = PureEnv - { inputText :: [Text], - outputText :: [Text], - pureREPL :: REPLEnv + { inputText :: [Text] + , outputText :: [Text] + , pureREPL :: REPLEnv } newtype PureREPL a = PureREPL {runPure :: CatchT (State PureEnv) a} @@ -26,25 +26,30 @@ instance MonadREPL PureREPL where ins <- gets inputText case ins of [] -> pure EOF - (t : ts) -> modify (\e -> e {inputText = ts}) >> pure (interpret t) + (t : ts) -> modify (\e -> e{inputText = ts}) >> pure (interpret t) - output t = modify $ \e -> e {outputText = render t : outputText e} + output t = modify $ \e -> e{outputText = render t : outputText e} prompt = pure () getEnv = gets pureREPL - setEnv e' = modify $ \e -> e {pureREPL = e'} + 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 ast _term typ -> pretty ast <> " : " <> Type.pretty typ - Defined ident typ -> ident <> " : " <> Type.pretty typ + Evaluated ast _term typ -> pretty ast <> renderType typ + Defined ident typ -> ident <> renderType typ Bye -> "Bye!" other -> pack (show other) +renderType :: Maybe Type.Type -> Text +renderType typ = case typ of + Nothing -> "" + Just t -> " : " <> Type.pretty t + instance MonadThrow PureREPL where throwM = throw |
