Don't duplicate token ids in lists

This commit is contained in:
Niels G. W. Serup 2024-09-21 19:25:36 +02:00
parent c588dc1f56
commit 8184160035
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
1 changed files with 9 additions and 2 deletions

View File

@ -38,8 +38,11 @@ newtype ComputationM' a = ComputationM { unComputationM :: WriterT [DependencyUn
type ComputationM a = ComputationM' (Token a) type ComputationM a = ComputationM' (Token a)
evalComputationM' :: Int -> ComputationM () -> ([DependencyUntyped], Int)
evalComputationM' top m = runState (execWriterT (unComputationM m)) top
evalComputationM :: ComputationM () -> [DependencyUntyped] 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 :: (Show u, Show a) => (Token a -> Dependency u a) -> ComputationM a
genDependency g = do genDependency g = do
@ -76,7 +79,11 @@ saveFile = runIO SaveFile
runPandoc = runIO RunPandoc runPandoc = runIO RunPandoc
mapComputationM :: (Show a, Show b) => (Token a -> ComputationM b) -> Token [a] -> ComputationM [b] 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 () where m :: ComputationM ()
m = do m = do
inp <- getListElem inp <- getListElem