✨
This commit is contained in:
16
a4/src/APL/InterpPure.hs
Normal file
16
a4/src/APL/InterpPure.hs
Normal 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)
|
Reference in New Issue
Block a user