Functor & Applicative instances for Compiler

This commit is contained in:
Jasper Van der Jeugt 2011-01-25 11:14:22 +01:00
parent 9b3e524128
commit e536a5961c
2 changed files with 11 additions and 1 deletions

View file

@ -14,7 +14,7 @@ module Hakyll.Core.Compiler.Internal
) where
import Prelude hiding ((.), id)
import Control.Applicative (Applicative, (<$>))
import Control.Applicative (Applicative, pure, (<*>), (<$>))
import Control.Monad.Reader (ReaderT, Reader, ask, runReaderT, runReader)
import Control.Monad ((<=<), liftM2)
import Data.Set (Set)
@ -58,6 +58,14 @@ data Compiler a b = Compiler
, compilerJob :: a -> CompilerM b
}
instance Functor (Compiler a) where
fmap f (Compiler d j) = Compiler d $ fmap f . j
instance Applicative (Compiler a) where
pure = Compiler (return S.empty) . const . return
(Compiler d1 f) <*> (Compiler d2 j) =
Compiler (liftM2 S.union d1 d2) $ \x -> f x <*> j x
instance Category Compiler where
id = Compiler (return S.empty) return
(Compiler d1 j1) . (Compiler d2 j2) =

View file

@ -109,6 +109,8 @@ route pattern route' = tellRoute $ ifMatch pattern route'
-- | Add a compiler that produces other compilers over time
--
-- TODO: Rename to metaCompile? Auto-generate identifier?
--
addCompilers :: (Binary a, Typeable a, Writable a)
=> Identifier
-- ^ Identifier for this compiler