@@ -0,0 +1,46 @@
1+-- | Internal structure of a Target, not exported outside of the library
2+--
3+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4+module Hakyll.Core.Target.Internal
5+ ( DependencyLookup
6+ , TargetM (..)
7+ , Target
8+ , runTarget
9+ ) where
10+
11+import Control.Monad.Trans (MonadIO)
12+import Control.Monad.Reader (ReaderT, runReaderT)
13+
14+import Hakyll.Core.Identifier
15+
16+-- | A lookup with which we can get dependencies
17+--
18+type DependencyLookup a = Identifier -> a
19+
20+-- | Environment for the target monad
21+--
22+data TargetEnvironment a = TargetEnvironment
23+ { targetIdentifier :: Identifier
24+ , targetDependencyLookup :: DependencyLookup a -- ^ Dependency lookup
25+ }
26+
27+-- | Monad for targets. In this monad, the user can compose targets and describe
28+-- how they should be created.
29+--
30+newtype TargetM a b = TargetM {unTargetM :: ReaderT (TargetEnvironment a) IO b}
31+ deriving (Monad, Functor, MonadIO)
32+
33+-- | Simplification of the 'TargetM' type for concrete cases: the type of the
34+-- returned item should equal the type of the dependencies.
35+--
36+type Target a = TargetM a a
37+
38+-- | Run a target, yielding an actual result.
39+--
40+runTarget :: Target a -> Identifier -> DependencyLookup a -> IO a
41+runTarget target id' lookup' = runReaderT (unTargetM target) env
42+ where
43+ env = TargetEnvironment
44+ { targetIdentifier = id'
45+ , targetDependencyLookup = lookup'
46+ }