From 0ddc5807cab7cf3b791b1de4cffe2b1165b2480d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 19 Jul 2026 13:56:21 +0200 Subject: Evaluation of Expr type --- src/Eval.hs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/Eval.hs') diff --git a/src/Eval.hs b/src/Eval.hs index 9ef8718..a918910 100644 --- a/src/Eval.hs +++ b/src/Eval.hs @@ -1,7 +1,7 @@ module Eval ( EvalInput(..), EvalError(..), textEvalError, - Eval, runEval, + Eval, runEval, eval, RepoRef(..), evalJobSet, @@ -13,6 +13,7 @@ module Eval ( ) where import Control.Monad +import Control.Monad.Catch import Control.Monad.Except import Control.Monad.Reader @@ -26,6 +27,7 @@ import System.FilePath import Config import Destination +import Expr import Job.Types import Repo @@ -51,6 +53,21 @@ runEval :: Eval a -> EvalInput -> IO (Either EvalError a) runEval action einput = runExceptT $ flip runReaderT einput action +eval :: forall ctx a. ctx -> Expr ctx a -> Eval a +eval ctx = \case + Pure x -> return x + App f x -> eval' f <*> eval' x + GetContext -> return ctx + AddDependency _ x -> eval' x + ExprIO act x -> do + x' <- eval' x + liftIO (handleIOError (\e -> return $ Left e) (Right <$> act x')) >>= \case + Left e -> throwError $ OtherEvalError $ "IO error: " <> T.pack (show e) + Right y -> return y + where + eval' :: forall b. Expr ctx b -> Eval b + eval' = eval ctx + repoRefLimit :: RepoDepLevel -> RepoRef -> Eval RepoRef repoRefLimit (RepoDepSubtree path) rref = do -- cgit v1.2.3