Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate empty; add mkEmpty #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.[oa]
*.hi
*~
dist/
.stack-work/
28 changes: 18 additions & 10 deletions Data/Configurator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Data.Configurator
, autoReloadGroups
, autoConfig
, empty
, mkEmpty
-- * Lookup functions
, lookup
, lookupDefault
Expand Down Expand Up @@ -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
Expand Down