From d3b32398b59bf11d29bccdea0b7136192d208491 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Fri, 27 Sep 2024 21:13:16 +0200 Subject: [PATCH] Implement DependencyRunner for MapComp --- byg/src/DependencyRunner.hs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/byg/src/DependencyRunner.hs b/byg/src/DependencyRunner.hs index 68e59aa..f014bcf 100644 --- a/byg/src/DependencyRunner.hs +++ b/byg/src/DependencyRunner.hs @@ -1,5 +1,7 @@ module DependencyRunner - ( runDeps + ( DepRunM + , runDeps + , runDepRunM ) where import Types (Value(..), Valuable(..)) @@ -9,7 +11,7 @@ import Evaluation.FunctionIO import Data.Map (Map) import qualified Data.Map as M -import Control.Monad.State (MonadState, MonadIO, StateT, runState, put, get, modify, liftIO) +import Control.Monad.State (MonadState, MonadIO, StateT, evalStateT, get, modify, liftIO) newtype DepRunM a = DepRunM { unDepRunM :: StateT (Map Int Value) IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadState (Map Int Value)) @@ -17,6 +19,9 @@ newtype DepRunM a = DepRunM { unDepRunM :: StateT (Map Int Value) IO a } runDeps :: [Dependency] -> DepRunM () runDeps = mapM_ runDep +runDepRunM :: DepRunM a -> IO a +runDepRunM m = evalStateT (unDepRunM m) M.empty + runDep :: Dependency -> DepRunM () runDep (Dependency a action b) = do input <- getTokenValue a @@ -91,4 +96,11 @@ runAction action input = case action of _ -> error "unexpected" MapComp subDeps innerInput innerOutput -> - undefined + case input of + List vs -> + (List <$>) $ flip mapM vs $ \v -> do + putTokenValue innerInput v + runDeps subDeps + getTokenValue innerOutput + _ -> + error "unexpected"