]> gitweb.michael.orlitzky.com - mailbox-count.git/blobdiff - src/OptionalConfiguration.hs
src/OptionalConfiguration.hs: use an explicit mappend.
[mailbox-count.git] / src / OptionalConfiguration.hs
index 2d74d27965e1281f0e816ae45500af9221f67440..31aa7f1f7d37566538b3db1dad9a5f9d3e0bd8cb 100644 (file)
@@ -19,8 +19,8 @@ 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 )
 import System.FilePath ( (</>) )
@@ -42,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
@@ -55,14 +55,30 @@ 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 Semigroup OptionalConfiguration where
+  -- | Combine @cfg1@ and @cfg2@, giving precedence to @cfg2@.
+  cfg1 <> cfg2 =
+    OptionalConfiguration
+      (merge_maybes (database cfg1) (database cfg2))
+      (merge_maybes (detail cfg1) (detail cfg2))
+      (merge_maybes (detail_query cfg1) (detail_query cfg2))
+      (merge_maybes (host cfg1) (host cfg2))
+      (merge_maybes (password cfg1) (password cfg2))
+      (merge_maybes (port cfg1) (port cfg2))
+      (merge_maybes (summary_query cfg1) (summary_query cfg2))
+      (merge_maybes (username cfg1) (username cfg2))
+
+
+-- | The Monoid instance essentially only provides the "empty
+--   configuration."
 instance Monoid OptionalConfiguration where
   -- | An empty OptionalConfiguration.
   mempty = OptionalConfiguration
@@ -74,18 +90,7 @@ instance Monoid OptionalConfiguration where
              Nothing
              Nothing
              Nothing
-
-  -- | Combine @cfg1@ and @cfg2@, giving precedence to @cfg2@.
-  cfg1 `mappend` cfg2 =
-    OptionalConfiguration
-      (merge_maybes (database cfg1) (database cfg2))
-      (merge_maybes (detail cfg1) (detail cfg2))
-      (merge_maybes (detail_query cfg1) (detail_query cfg2))
-      (merge_maybes (host cfg1) (host cfg2))
-      (merge_maybes (password cfg1) (password cfg2))
-      (merge_maybes (port cfg1) (port cfg2))
-      (merge_maybes (summary_query cfg1) (summary_query cfg2))
-      (merge_maybes (username cfg1) (username cfg2))
+  mappend = (<>)
 
 
 -- | Obtain an OptionalConfiguration from mailbox-countrc in either