From 1d1f0efc7de1eaa0c8a6b503892c2f950008fde6 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 28 Oct 2025 20:14:16 +0100 Subject: wip: port REPL from minilang --- lambda-calcul/haskell/src/Minilang/REPL/Purer.hs | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lambda-calcul/haskell/src/Minilang/REPL/Purer.hs (limited to 'lambda-calcul/haskell/src/Minilang/REPL/Purer.hs') diff --git a/lambda-calcul/haskell/src/Minilang/REPL/Purer.hs b/lambda-calcul/haskell/src/Minilang/REPL/Purer.hs new file mode 100644 index 0000000..9e4bd22 --- /dev/null +++ b/lambda-calcul/haskell/src/Minilang/REPL/Purer.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +module Minilang.REPL.Purer where + + +import Control.Monad.Catch +import Control.Monad.Catch.Pure (CatchT (..)) +import Control.Monad.State +import Minilang.REPL.Types + + +data PurerEnv = PurerEnv + { inputs :: [In] + , outputs :: [Out] + , purerREPL :: REPLEnv + } + +newtype PurerREPL a = PurerREPL { runPurer :: CatchT (State PurerEnv) a } + deriving (Functor, Applicative, Monad, MonadState PurerEnv, MonadCatch, MonadThrow) + +instance MonadREPL PurerREPL where + input = do + ins <- inputs <$> get + case ins of + [] -> pure EOF + (t:ts) -> modify (\ e -> e { inputs = ts }) >> pure t + + output t = modify $ \ e -> e { outputs = t : outputs e } + prompt = pure () + getEnv = get >>= pure . purerREPL + setEnv e' = modify $ \ e -> e { purerREPL = e' } + load f = pure $ Left $ REPLError $ "cannot load file " <> f <> " in Pure interpreter" -- cgit v1.3.1