From 81841600351ccd8bb50f9b0969abdcac78f7ba3d Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Sat, 21 Sep 2024 19:25:36 +0200 Subject: [PATCH] Don't duplicate token ids in lists --- byg/src/ComputationM.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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