diff --git a/byg/src/ComputationM.hs b/byg/src/ComputationM.hs index 723f49a..fb3ac8b 100644 --- a/byg/src/ComputationM.hs +++ b/byg/src/ComputationM.hs @@ -38,8 +38,11 @@ newtype ComputationM' a = ComputationM { unComputationM :: WriterT [DependencyUn type ComputationM a = ComputationM' (Token a) +evalComputationM' :: Int -> ComputationM () -> ([DependencyUntyped], Int) +evalComputationM' top m = runState (execWriterT (unComputationM m)) top + evalComputationM :: ComputationM () -> [DependencyUntyped] -evalComputationM m = evalState (execWriterT (unComputationM m)) 0 +evalComputationM m = fst (evalComputationM' 0 m) genDependency :: (Show u, Show a) => (Token a -> Dependency u a) -> ComputationM a genDependency g = do @@ -76,7 +79,11 @@ saveFile = runIO SaveFile runPandoc = runIO RunPandoc mapComputationM :: (Show a, Show b) => (Token a -> ComputationM b) -> Token [a] -> ComputationM [b] -mapComputationM f input = genDependency (Dependency input (MapComp (evalComputationM m))) +mapComputationM f input = do + top <- get + let (res, top') = evalComputationM' top m + put top' + genDependency (Dependency input (MapComp res)) where m :: ComputationM () m = do inp <- getListElem