This commit is contained in:
2024-09-28 15:13:45 +02:00
parent 31a4cdaca8
commit 0dccdc0a95
10 changed files with 549 additions and 0 deletions

16
a4/src/APL/InterpPure.hs Normal file
View File

@ -0,0 +1,16 @@
module APL.InterpPure (runEval) where
import APL.Monad
runEval :: EvalM a -> ([String], Either Error a)
runEval = runEval' envEmpty stateInitial
where
runEval' :: Env -> State -> EvalM a -> ([String], Either Error a)
runEval' _ _ (Pure x) = ([], pure x)
runEval' r s (Free (ReadOp k)) = runEval' r s $ k r
runEval' r s (Free (StateGetOp k)) = runEval' r s $ k s
runEval' r _ (Free (StatePutOp s' m)) = runEval' r s' m
runEval' r s (Free (PrintOp p m)) =
let (ps, res) = runEval' r s m
in (p : ps, res)
runEval' _ _ (Free (ErrorOp e)) = ([], Left e)