summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/src/Minilang/REPL/Purer.hs
diff options
context:
space:
mode:
authorArnaud Bailly <arnaud@pankzsoft.com>2025-10-28 20:14:16 +0100
committerArnaud Bailly <arnaud@pankzsoft.com>2025-10-28 20:14:16 +0100
commit1d1f0efc7de1eaa0c8a6b503892c2f950008fde6 (patch)
treebd2e2ea5963d8a208d302854502f580d8ffd73cb /lambda-calcul/haskell/src/Minilang/REPL/Purer.hs
parenta210419fd60c00d011f70fb1b968031621e4c01a (diff)
downloadlambda-nantes-1d1f0efc7de1eaa0c8a6b503892c2f950008fde6.tar.gz
wip: port REPL from minilang
Diffstat (limited to 'lambda-calcul/haskell/src/Minilang/REPL/Purer.hs')
-rw-r--r--lambda-calcul/haskell/src/Minilang/REPL/Purer.hs31
1 files changed, 31 insertions, 0 deletions
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"