on master help sign in
Add a snapshot state to target monad
commita1043203bb4ef5bc1af4c9a8957af36d163f03fb authorJasper Van der Jeugt <jaspervdj@gmail.com> dateMon 27 Dec 2010, 18:38 (16 years ago) parente07014b
1 file changed+15−3
src/Hakyll/Core/Target/Internal.hs+15−3
src/Hakyll/Core/Target/Internal.hs+15−3
@@ -12,6 +12,7 @@ module Hakyll.Core.Target.Internal
1212import Control.Applicative (Applicative)
1313import Control.Monad.Trans (MonadIO)
1414import Control.Monad.Reader (ReaderT, runReaderT)
15+import Control.Monad.State (StateT, evalStateT)
1516
1617import Hakyll.Core.Identifier
1718import Hakyll.Core.ResourceProvider
@@ -30,11 +31,18 @@ data TargetEnvironment a = TargetEnvironment
3031 , targetStore :: Store -- ^ Store for caching
3132 }
3233
34+-- | State for the target monad
35+--
36+data TargetState = TargetState
37+ { targetSnapshot :: Int -- ^ Snapshot ID
38+ }
39+
3340-- | Monad for targets. In this monad, the user can compose targets and describe
3441-- how they should be created.
3542--
36−newtype TargetM a b = TargetM {unTargetM :: ReaderT (TargetEnvironment a) IO b}
37− deriving (Monad, Functor, Applicative, MonadIO)
43+newtype TargetM a b = TargetM
44+ { unTargetM :: ReaderT (TargetEnvironment a) (StateT TargetState IO) b
45+ } deriving (Monad, Functor, Applicative, MonadIO)
3846
3947-- | Simplification of the 'TargetM' type for concrete cases: the type of the
4048-- returned item should equal the type of the dependencies.
@@ -49,7 +57,8 @@ runTarget :: Target a
4957 -> ResourceProvider
5058 -> Store
5159 -> IO a
52−runTarget target id' lookup' provider store = runReaderT (unTargetM target) env
60+runTarget target id' lookup' provider store =
61+ evalStateT (runReaderT (unTargetM target) env) state
5362 where
5463 env = TargetEnvironment
5564 { targetIdentifier = id'
@@ -57,3 +66,6 @@ runTarget target id' lookup' provider store = runReaderT (unTargetM target) env
5766 , targetResourceProvider = provider
5867 , targetStore = store
5968 }
69+ state = TargetState
70+ { targetSnapshot = 0
71+ }