on master help sign in
Add a snapshot state to target monad
a104320Jasper Van der Jeugt
src/Hakyll/Core/Target/Internal.hs+15−3
@@ -12,6 +12,7 @@ module Hakyll.Core.Target.Internal
12import Control.Applicative (Applicative)
12import Control.Applicative (Applicative)
13import Control.Monad.Trans (MonadIO)
13import Control.Monad.Trans (MonadIO)
14import Control.Monad.Reader (ReaderT, runReaderT)
14import Control.Monad.Reader (ReaderT, runReaderT)
15+import Control.Monad.State (StateT, evalStateT)
15
16
16import Hakyll.Core.Identifier
17import Hakyll.Core.Identifier
17import Hakyll.Core.ResourceProvider
18import Hakyll.Core.ResourceProvider
@@ -30,11 +31,18 @@ data TargetEnvironment a = TargetEnvironment
30 , targetStore :: Store -- ^ Store for caching
31 , targetStore :: Store -- ^ Store for caching
31 }
32 }
32
33
34+-- | State for the target monad
35+--
36+data TargetState = TargetState
37+ { targetSnapshot :: Int -- ^ Snapshot ID
38+ }
39+
33-- | Monad for targets. In this monad, the user can compose targets and describe
40-- | Monad for targets. In this monad, the user can compose targets and describe
34-- how they should be created.
41-- how they should be created.
35--
42--
43+newtype TargetM a b = TargetM
36−newtype TargetM a b = TargetM {unTargetM :: ReaderT (TargetEnvironment a) IO b}
44+ { unTargetM :: ReaderT (TargetEnvironment a) (StateT TargetState IO) b
37− deriving (Monad, Functor, Applicative, MonadIO)
45+ } deriving (Monad, Functor, Applicative, MonadIO)
38
46
39-- | Simplification of the 'TargetM' type for concrete cases: the type of the
47-- | Simplification of the 'TargetM' type for concrete cases: the type of the
40-- returned item should equal the type of the dependencies.
48-- returned item should equal the type of the dependencies.
@@ -49,7 +57,8 @@ runTarget :: Target a
49 -> ResourceProvider
57 -> ResourceProvider
50 -> Store
58 -> Store
51 -> IO a
59 -> 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
53 where
62 where
54 env = TargetEnvironment
63 env = TargetEnvironment
55 { targetIdentifier = id'
64 { targetIdentifier = id'
@@ -57,3 +66,6 @@ runTarget target id' lookup' provider store = runReaderT (unTargetM target) env
57 , targetResourceProvider = provider
66 , targetResourceProvider = provider
58 , targetStore = store
67 , targetStore = store
59 }
68 }
69+ state = TargetState
70+ { targetSnapshot = 0
71+ }