From daacf2e6fa263d9ce50b177c5fdc1820d35b64a1 Mon Sep 17 00:00:00 2001 From: "Niels G. W. Serup" Date: Tue, 24 Sep 2024 23:09:35 +0200 Subject: [PATCH] Swap DepGenM and DepGenM' --- byg/src/DependencyGenerator.hs | 50 +++++++++++++++++----------------- byg/src/SiteGenerator.hs | 4 +-- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/byg/src/DependencyGenerator.hs b/byg/src/DependencyGenerator.hs index 9c80d89..2d7fa20 100644 --- a/byg/src/DependencyGenerator.hs +++ b/byg/src/DependencyGenerator.hs @@ -31,21 +31,21 @@ import Types.Dependency (Action(..), Dependency, makeDependency) import Control.Monad.State (MonadState, State, runState, put, get) import Control.Monad.Writer (MonadWriter, WriterT, execWriterT, tell) -newtype DepGenM' a = DepGenM { unDepGenM :: WriterT [Dependency] (State Int) a } +newtype DepGenM a = DepGenM { unDepGenM :: WriterT [Dependency] (State Int) a } deriving (Functor, Applicative, Monad, MonadState Int, MonadWriter [Dependency]) -type DepGenM a = DepGenM' (Token a) +type DepGenM' a = DepGenM (Token a) -evalDepGenM' :: Int -> DepGenM' () -> ([Dependency], Int) +evalDepGenM' :: Int -> DepGenM () -> ([Dependency], Int) evalDepGenM' top m = runState (execWriterT (unDepGenM m)) top -evalDepGenM :: DepGenM' () -> [Dependency] +evalDepGenM :: DepGenM () -> [Dependency] evalDepGenM m = fst (evalDepGenM' 0 m) -tellDep :: Dependency -> DepGenM' () +tellDep :: Dependency -> DepGenM () tellDep dep = tell [dep] -genDependencyM :: (Token a -> DepGenM' Dependency) -> DepGenM a +genDependencyM :: (Token a -> DepGenM Dependency) -> DepGenM' a genDependencyM f = do top <- get let top' = top + 1 @@ -55,26 +55,26 @@ genDependencyM f = do tellDep result pure target -genDependency :: (Token a -> Dependency) -> DepGenM a +genDependency :: (Token a -> Dependency) -> DepGenM' a genDependency f = genDependencyM (pure . f) -inject :: Valuable a => a -> DepGenM a +inject :: Valuable a => a -> DepGenM' a inject x = genDependency (makeDependency NoToken (Inject (toValue x))) -getListElem :: Token [a] -> DepGenM a +getListElem :: Token [a] -> DepGenM' a getListElem outer = genDependency (makeDependency outer GetListElem) -setListElem :: Token a -> Token [a] -> DepGenM' () +setListElem :: Token a -> Token [a] -> DepGenM () setListElem a outer = do tellDep (makeDependency a SetListElem outer) -runFunction :: Function -> Token a -> DepGenM b +runFunction :: Function -> Token a -> DepGenM' b runFunction f input = genDependency (makeDependency input (Function f)) -runFunctionIO :: FunctionIO -> Token a -> DepGenM b +runFunctionIO :: FunctionIO -> Token a -> DepGenM' b runFunctionIO f input = genDependency (makeDependency input (FunctionIO f)) -mapDepGenM :: (Token a -> DepGenM b) -> Token [a] -> DepGenM [b] +mapDepGenM :: (Token a -> DepGenM' b) -> Token [a] -> DepGenM' [b] mapDepGenM f input = genDependencyM $ \target -> do top <- get let (res, top') = evalDepGenM' top $ do @@ -84,49 +84,49 @@ mapDepGenM f input = genDependencyM $ \target -> do put top' pure (makeDependency input (MapComp res) target) -mapDepGenM_ :: (Token a -> DepGenM' ()) -> Token [a] -> DepGenM' () +mapDepGenM_ :: (Token a -> DepGenM ()) -> Token [a] -> DepGenM () mapDepGenM_ f input = do _ <- mapDepGenM (\x -> f x >> pure NoToken) input pure () -filterDepGenM :: (Token a -> DepGenM Bool) -> Token [a] -> DepGenM [a] +filterDepGenM :: (Token a -> DepGenM' Bool) -> Token [a] -> DepGenM' [a] filterDepGenM f input = do conds <- mapDepGenM f input genDependency (makeDependency (TupleToken input conds) FilterComp) -joinPaths :: Token (FilePath, FilePath) -> DepGenM FilePath +joinPaths :: Token (FilePath, FilePath) -> DepGenM' FilePath joinPaths = runFunction JoinPaths -isImageFilename :: Token FilePath -> DepGenM Bool +isImageFilename :: Token FilePath -> DepGenM' Bool isImageFilename = runFunction IsImageFilename -convertedImageFilename :: Token FilePath -> DepGenM FilePath +convertedImageFilename :: Token FilePath -> DepGenM' FilePath convertedImageFilename = runFunction ConvertedImageFilename -applyTemplate :: Token (Template, String) -> DepGenM String +applyTemplate :: Token (Template, String) -> DepGenM' String applyTemplate = runFunction ApplyTemplate -listDirectory :: Token FilePath -> DepGenM [FilePath] +listDirectory :: Token FilePath -> DepGenM' [FilePath] listDirectory = runFunctionIO ListDirectory -readTemplate :: Token FilePath -> DepGenM Template +readTemplate :: Token FilePath -> DepGenM' Template readTemplate = runFunctionIO ReadTemplate -convertImage :: Token ((FilePath, FilePath), ImageConversionSettings) -> DepGenM' () +convertImage :: Token ((FilePath, FilePath), ImageConversionSettings) -> DepGenM () convertImage input = do _ <- runFunctionIO ConvertImage input pure () -saveFile :: Token (String, FilePath) -> DepGenM' () +saveFile :: Token (String, FilePath) -> DepGenM () saveFile input = do _ <- runFunctionIO SaveFile input pure () -makeDir :: Token FilePath -> DepGenM' () +makeDir :: Token FilePath -> DepGenM () makeDir input = do _ <- runFunctionIO MakeDir input pure () -runPandoc :: Token FilePath -> DepGenM String +runPandoc :: Token FilePath -> DepGenM' String runPandoc = runFunctionIO RunPandoc diff --git a/byg/src/SiteGenerator.hs b/byg/src/SiteGenerator.hs index afb5035..06e4dd1 100644 --- a/byg/src/SiteGenerator.hs +++ b/byg/src/SiteGenerator.hs @@ -3,7 +3,7 @@ module SiteGenerator (generateSite) where import Types import DependencyGenerator -handleRecipeDir :: Token Template -> Token FilePath -> DepGenM' () +handleRecipeDir :: Token Template -> Token FilePath -> DepGenM () handleRecipeDir _template dir = do dirContents <- listDirectory dir imageFilenames <- filterDepGenM isImageFilename dirContents @@ -12,7 +12,7 @@ handleRecipeDir _template dir = do settings <- inject $ ResizeToWidth 800 convertImage $ TupleToken files settings -generateSite :: DepGenM' () +generateSite :: DepGenM () generateSite = do outputDir <- inject "site" makeDir outputDir