global-config-0.3.1: Global mutable configuration

Safe HaskellSafe-Infered

Data.Global.Config

Description

Main problem in haskell is "creepy" enviroment variables passed to all functions. It's safe but tedious.

GlobalConfig trying to solve this problem and propose common pattern to work with configurations. It has been tested and proved to be very useful in production.

 {-# LANGUAGE DeriveDataTypeable #-}
 
 module Main (main) where
 
 import Data.Typeable (Typeable)
 import Data.Default
 import Data.Global.Config
 
 data Config = Config { configInt :: Int, configBool :: Bool }
    deriving (Show, Typeable)
 
 instance Default Config
    def = Config 0 False
 
 instance GlobalConfig Config where
    onSetConfig = print
    
 main :: IO ()
 main = do
    -- try to read unitialized config
    c1 <- getConfig 
    -- Config {configInt=0, configBool=False}
    
    -- set config and read it
    setConfig $ Config 1 True
    -- Config {configInt=1, configBool=True}
    c2 <- getConfig
    print (c1 :: Config)
    -- Config {configInt=1, configBool=True}

Synopsis

Documentation

class (Default a, Typeable a) => GlobalConfig a whereSource

Global configuration class

Methods

setConfig :: MonadIO m => a -> m ()Source

Init global config

onSetConfig :: MonadIO m => a -> m ()Source

Set config handler

getConfig :: MonadIO m => m aSource

Get global config