diff options
| author | Joey Hess <joey@kitenet.net> | 2014-04-10 17:22:32 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-04-10 17:23:43 -0400 |
| commit | 25942fb0cca0ca90933026bf959506e099ff95a4 (patch) | |
| tree | 2f84378c71abaa4458c5078e8cb8e6726bffbefd /Propellor/Types.hs | |
| parent | 5acaf8758f752574140dd79de7996d91a81d1cd4 (diff) | |
Propellor monad is a Reader for HostAttr
So far, the hostname is only used to improve a message in withPrivData,
but I anticipate using HostAttr for a lot more.
Diffstat (limited to 'Propellor/Types.hs')
| -rw-r--r-- | Propellor/Types.hs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Propellor/Types.hs b/Propellor/Types.hs index 3be10d3f..b1632923 100644 --- a/Propellor/Types.hs +++ b/Propellor/Types.hs @@ -1,20 +1,53 @@ +{-# LANGUAGE PackageImports #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} + module Propellor.Types where import Data.Monoid +import Control.Applicative import System.Console.ANSI +import "mtl" Control.Monad.Reader +import "MonadCatchIO-transformers" Control.Monad.CatchIO type HostName = String type GroupName = String type UserName = String +-- | The core data type of Propellor, this reprecents a property +-- that the system should have, and an action to ensure it has the +-- property. data Property = Property { propertyDesc :: Desc -- | must be idempotent; may run repeatedly - , propertySatisfy :: IO Result + , propertySatisfy :: Propellor Result } +-- | A property that can be reverted. data RevertableProperty = RevertableProperty Property Property +-- | Propellor's monad provides read-only access to attributes of the +-- system. +newtype Propellor a = Propellor { runWithHostAttr :: ReaderT HostAttr IO a } + deriving + ( Monad + , Functor + , Applicative + , MonadReader HostAttr + , MonadIO + , MonadCatchIO + ) + +-- | The attributes of a system. For example, its hostname. +newtype HostAttr = HostAttr + { _hostname :: HostName + } + +mkHostAttr :: HostName -> HostAttr +mkHostAttr = HostAttr + +getHostName :: Propellor HostName +getHostName = asks _hostname + class IsProp p where -- | Sets description. describe :: p -> Desc -> p |
