diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-07-19 13:56:21 +0200 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-07-24 21:17:52 +0200 |
| commit | 0ddc5807cab7cf3b791b1de4cffe2b1165b2480d (patch) | |
| tree | 3236c63b27cfe9a33f62c498f932ddc2dfc29acd /src/Eval.hs | |
| parent | e736b0a3ee8737b35fa79af644ca21cebafa76ef (diff) | |
Evaluation of Expr type
Diffstat (limited to 'src/Eval.hs')
| -rw-r--r-- | src/Eval.hs | 19 |
1 files changed, 18 insertions, 1 deletions
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 |