X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FOptionalConfiguration.hs;h=d9627928c82b4b856e2ad0feedf66b991db22f16;hb=refs%2Ftags%2F0.0.5;hp=16a61bf802630250feb0dad9029d4e12cf1615e5;hpb=17ce59153f9b7aef917bb4395cf8fb992a6f738c;p=mailbox-count.git diff --git a/src/OptionalConfiguration.hs b/src/OptionalConfiguration.hs index 16a61bf..d962792 100644 --- a/src/OptionalConfiguration.hs +++ b/src/OptionalConfiguration.hs @@ -19,8 +19,7 @@ import qualified Data.Configurator as DC ( load, lookup ) import Data.Data ( Data ) -import Data.Typeable ( Typeable ) -import Data.Monoid ( Monoid(..) ) +import Data.Monoid ( Monoid() ) import Data.Semigroup ( Semigroup( (<>) ) ) import Paths_mailbox_count ( getSysconfDir ) import System.Directory ( getHomeDirectory ) @@ -43,7 +42,7 @@ data OptionalConfiguration = port :: Maybe Int, summary_query :: Maybe String, username :: Maybe String } - deriving (Show, Data, Typeable) + deriving (Show, Data) -- | Combine two Maybes into one, essentially mashing them @@ -56,26 +55,14 @@ merge_maybes Nothing (Just x) = Just x merge_maybes (Just _) (Just y) = Just y --- | The Monoid instance for these lets us "combine" two --- OptionalConfigurations. The "combine" operation that we'd like to --- perform is, essentially, to mash them together. So if we have two +-- | The Semigroup instance for these lets us "combine" two +-- configurations. The "combine" operation that we'd like to perform +-- is, essentially, to mash them together. So if we have two -- OptionalConfigurations, each half full, we could combine them -- into one big one. -- -- This is used to merge command-line and config-file settings. -- -instance Monoid OptionalConfiguration where - -- | An empty OptionalConfiguration. - mempty = OptionalConfiguration - Nothing - Nothing - Nothing - Nothing - Nothing - Nothing - Nothing - Nothing - instance Semigroup OptionalConfiguration where -- | Combine @cfg1@ and @cfg2@, giving precedence to @cfg2@. cfg1 <> cfg2 = @@ -90,6 +77,22 @@ instance Semigroup OptionalConfiguration where (merge_maybes (username cfg1) (username cfg2)) +-- | The Monoid instance essentially only provides the "empty +-- configuration." +instance Monoid OptionalConfiguration where + -- | An empty OptionalConfiguration. + mempty = OptionalConfiguration + Nothing + Nothing + Nothing + Nothing + Nothing + Nothing + Nothing + Nothing + mappend = (<>) + + -- | Obtain an OptionalConfiguration from mailbox-countrc in either -- the global configuration directory or the user's home -- directory. The one in $HOME is prefixed by a dot so that it is