summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Rules/Internal.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Core/Rules/Internal.hs')
-rw-r--r--src/Hakyll/Core/Rules/Internal.hs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Hakyll/Core/Rules/Internal.hs b/src/Hakyll/Core/Rules/Internal.hs
index a7c2059..72166c8 100644
--- a/src/Hakyll/Core/Rules/Internal.hs
+++ b/src/Hakyll/Core/Rules/Internal.hs
@@ -16,6 +16,7 @@ import Control.Applicative (Applicative, (<$>))
import Control.Monad.Reader (ask)
import Control.Monad.RWS (RWST, runRWST)
import Control.Monad.Trans (liftIO)
+import Data.Map (Map)
import qualified Data.Map as M
import Data.Monoid (Monoid, mappend, mempty)
import Data.Set (Set)
@@ -97,15 +98,26 @@ runRules rules provider = do
(_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState
-- Ensure compiler uniqueness
- let ruleSet' = ruleSet
- { rulesCompilers = M.toList $
- M.fromListWith (flip const) (rulesCompilers ruleSet)
- }
+ uniqueCompilers <- case fromListUnique (rulesCompilers ruleSet) of
+ Right m -> return m
+ Left id' -> error $
+ "Hakyll.Core.Rules.Internal.runRules: duplicate compiler for " ++
+ show id'
- return ruleSet'
+ return ruleSet {rulesCompilers = M.toList uniqueCompilers}
where
env = RulesRead
{ rulesProvider = provider
, rulesMatches = []
, rulesVersion = Nothing
}
+
+
+--------------------------------------------------------------------------------
+fromListUnique :: Ord k => [(k, v)] -> Either k (Map k v)
+fromListUnique = go M.empty
+ where
+ go m [] = Right m
+ go m ((k, v) : zs) = case M.lookup k m of
+ Nothing -> go (M.insert k v m) zs
+ Just _ -> Left k