diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98eb813 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.[oa] +*.hi +*~ +dist/ +.stack-work/ diff --git a/Data/Configurator.hs b/Data/Configurator.hs index 96b88f3..8428f10 100644 --- a/Data/Configurator.hs +++ b/Data/Configurator.hs @@ -39,6 +39,7 @@ module Data.Configurator , autoReloadGroups , autoConfig , empty + , mkEmpty -- * Lookup functions , lookup , lookupDefault @@ -384,19 +385,26 @@ notifySubscribers BaseConfig{..} m m' subs = H.foldrWithKey go (return ()) subs forM_ (matching changedOrGone) $ \(n',v) -> mapM_ (notify p n' v) acts -- | A completely empty configuration. +{-# DEPRECATED empty "Modifying empty with, e.g., addToConfig, breaks referential transparency. Use mkEmpty instead." #-} empty :: Config -empty = Config "" $ unsafePerformIO $ do - p <- newIORef [] - m <- newIORef H.empty - s <- newIORef H.empty - return BaseConfig { - cfgAuto = Nothing - , cfgPaths = p - , cfgMap = m - , cfgSubs = s - } +empty = Config "" $ unsafePerformIO mkEmptyBase {-# NOINLINE empty #-} +mkEmpty :: IO Config +mkEmpty = Config "" <$> mkEmptyBase + +mkEmptyBase :: IO BaseConfig +mkEmptyBase = do + p <- newIORef [] + m <- newIORef H.empty + s <- newIORef H.empty + return $ BaseConfig { + cfgAuto = Nothing + , cfgPaths = p + , cfgMap = m + , cfgSubs = s + } + -- $format -- -- A configuration file consists of a series of directives and