on master help sign in
Functor & Applicative instances for Compiler
e536a59Jasper Van der Jeugt
src/Hakyll/Core/Compiler/Internal.hs+9−1
@@ -14,7 +14,7 @@ module Hakyll.Core.Compiler.Internal
14 ) where
14 ) where
15
15
16import Prelude hiding ((.), id)
16import Prelude hiding ((.), id)
17−import Control.Applicative (Applicative, (<$>))
17+import Control.Applicative (Applicative, pure, (<*>), (<$>))
18import Control.Monad.Reader (ReaderT, Reader, ask, runReaderT, runReader)
18import Control.Monad.Reader (ReaderT, Reader, ask, runReaderT, runReader)
19import Control.Monad ((<=<), liftM2)
19import Control.Monad ((<=<), liftM2)
20import Data.Set (Set)
20import Data.Set (Set)
@@ -58,6 +58,14 @@ data Compiler a b = Compiler
58 , compilerJob :: a -> CompilerM b
58 , compilerJob :: a -> CompilerM b
59 }
59 }
60
60
61+instance Functor (Compiler a) where
62+ fmap f (Compiler d j) = Compiler d $ fmap f . j
63+
64+instance Applicative (Compiler a) where
65+ pure = Compiler (return S.empty) . const . return
66+ (Compiler d1 f) <*> (Compiler d2 j) =
67+ Compiler (liftM2 S.union d1 d2) $ \x -> f x <*> j x
68+
61instance Category Compiler where
69instance Category Compiler where
62 id = Compiler (return S.empty) return
70 id = Compiler (return S.empty) return
63 (Compiler d1 j1) . (Compiler d2 j2) =
71 (Compiler d1 j1) . (Compiler d2 j2) =
src/Hakyll/Core/Rules.hs+2
@@ -109,6 +109,8 @@ route pattern route' = tellRoute $ ifMatch pattern route'
109
109
110-- | Add a compiler that produces other compilers over time
110-- | Add a compiler that produces other compilers over time
111--
111--
112+-- TODO: Rename to metaCompile? Auto-generate identifier?
113+--
112addCompilers :: (Binary a, Typeable a, Writable a)
114addCompilers :: (Binary a, Typeable a, Writable a)
113 => Identifier
115 => Identifier
114 -- ^ Identifier for this compiler
116 -- ^ Identifier for this compiler