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