on master help sign in
Functor & Applicative instances for Compiler
commite536a5961c8ba795660c37349091c4a9427876fe authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 25 Jan 2011, 11:14 (16 years ago) parent9b3e524
2 files changed+11−1
src/Hakyll/Core/Compiler/Internal.hs+9−1 src/Hakyll/Core/Rules.hs+2
src/Hakyll/Core/Compiler/Internal.hs+9−1
@@ -14,7 +14,7 @@ module Hakyll.Core.Compiler.Internal
1414 ) where
1515
1616import Prelude hiding ((.), id)
17−import Control.Applicative (Applicative, (<$>))
17+import Control.Applicative (Applicative, pure, (<*>), (<$>))
1818import Control.Monad.Reader (ReaderT, Reader, ask, runReaderT, runReader)
1919import Control.Monad ((<=<), liftM2)
2020import Data.Set (Set)
@@ -58,6 +58,14 @@ data Compiler a b = Compiler
5858 , compilerJob :: a -> CompilerM b
5959 }
6060
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+
6169instance Category Compiler where
6270 id = Compiler (return S.empty) return
6371 (Compiler d1 j1) . (Compiler d2 j2) =
src/Hakyll/Core/Rules.hs+2
@@ -109,6 +109,8 @@ route pattern route' = tellRoute $ ifMatch pattern route'
109109
110110-- | Add a compiler that produces other compilers over time
111111--
112+-- TODO: Rename to metaCompile? Auto-generate identifier?
113+--
112114addCompilers :: (Binary a, Typeable a, Writable a)
113115 => Identifier
114116 -- ^ Identifier for this compiler