Functor & Applicative instances for Compiler
This commit is contained in:
parent
9b3e524128
commit
e536a5961c
2 changed files with 11 additions and 1 deletions
|
@ -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) =
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue