packages feed

global-config 0.2.1 → 0.3.0

raw patch · 3 files changed

+11/−8 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Global.Config: class (Default a, Typeable a) => GlobalConfig a where setConfig e = do { stubConfig `writeIORef` e; onSetConfig e } onSetConfig _ = return () getConfig = readIORef stubConfig stubConfig = declareIORef "" def
+ Data.Global.Config: class (Default a, Typeable a) => GlobalConfig a where setConfig e = do { liftIO $ stubConfig `writeIORef` e; onSetConfig e } onSetConfig _ = return () getConfig = liftIO $ readIORef stubConfig stubConfig = declareIORef "" def
- Data.Global.Config: getConfig :: GlobalConfig a => IO a
+ Data.Global.Config: getConfig :: (GlobalConfig a, MonadIO m) => m a
- Data.Global.Config: onSetConfig :: GlobalConfig a => a -> IO ()
+ Data.Global.Config: onSetConfig :: (GlobalConfig a, MonadIO m) => a -> m ()
- Data.Global.Config: setConfig :: GlobalConfig a => a -> IO ()
+ Data.Global.Config: setConfig :: (GlobalConfig a, MonadIO m) => a -> m ()

Files

global-config.cabal view
@@ -1,5 +1,5 @@ name:           global-config
-version:        0.2.1
+version:        0.3.0
 cabal-version:  >= 1.8
 build-type:     Simple
 author:         Alexander Dorofeev <aka.spin@gmail.com>spin
@@ -23,7 +23,8 @@   hs-source-dirs:   src
   build-depends:    base >= 4 && < 5,
                    global-variables,
-                   data-default
+                   data-default,
+                   transformers
   ghc-options:      -Wall
   exposed-modules:  Data.Global.Config
 
src/Data/Global/Config.hs view
@@ -40,6 +40,8 @@     GlobalConfig (setConfig, onSetConfig, getConfig)
 ) where
 
+import Control.Monad.IO.Class (MonadIO, liftIO)
+
 import Data.Typeable (Typeable)
 import Data.Global (declareIORef)
 import Data.IORef (IORef, writeIORef, readIORef)
@@ -48,18 +50,18 @@ -- | Global configuration class
 class (Default a, Typeable a) => GlobalConfig a where
     -- | Init global config
-    setConfig :: a -> IO ()
+    setConfig :: MonadIO m => a -> m ()
     setConfig e = do
-        stubConfig `writeIORef` e
+        liftIO $ stubConfig `writeIORef` e
         onSetConfig e 
     
     -- | Set config handler
-    onSetConfig :: a -> IO ()
+    onSetConfig :: MonadIO m => a -> m ()
     onSetConfig _ = return ()
     
     -- | Get global config
-    getConfig :: IO a
-    getConfig = readIORef stubConfig
+    getConfig :: MonadIO m => m a
+    getConfig = liftIO $ readIORef stubConfig
     
     -- | Stub enviroment
     stubConfig :: IORef a
test/Main.hs view
@@ -56,7 +56,7 @@     def = Config 0 ""
     
 instance GlobalConfig Config where
-    onSetConfig = print
+    onSetConfig = liftIO . print