From: Michael Orlitzky Date: Wed, 24 Aug 2022 12:01:40 +0000 (-0400) Subject: src/OptionalConfiguration.hs: add Semigroup instance. X-Git-Tag: 0.0.2~20 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=list-remote-forwards.git;a=commitdiff_plain;h=573cbd586b1322adc779aed5d83dcb89b06b4fb4 src/OptionalConfiguration.hs: add Semigroup instance. ...Now that Semigroup is a superclass of Monoid. --- diff --git a/src/OptionalConfiguration.hs b/src/OptionalConfiguration.hs index 072f25b..3dc26bd 100644 --- a/src/OptionalConfiguration.hs +++ b/src/OptionalConfiguration.hs @@ -58,7 +58,7 @@ merge_maybes Nothing (Just x) = Just x merge_maybes (Just _) (Just y) = Just y --- | The Monoid instance for these lets us "combine" two +-- | The Semigroup 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 -- OptionalConfigurations, each half full, we could combine them @@ -66,20 +66,10 @@ merge_maybes (Just _) (Just y) = Just y -- -- This is used to merge command-line and config-file settings. -- -instance Monoid OptionalConfiguration where - -- | An empty OptionalConfiguration. - mempty = OptionalConfiguration - Nothing - Nothing - (MxList []) - Nothing - Nothing - Nothing - Nothing - Nothing +instance Semigroup OptionalConfiguration where -- | Combine @cfg1@ and @cfg2@, giving precedence to @cfg2@. - cfg1 `mappend` cfg2 = + cfg1 <> cfg2 = OptionalConfiguration (merge_maybes (database cfg1) (database cfg2)) (merge_maybes (domain_query cfg1) (domain_query cfg2)) @@ -96,6 +86,21 @@ instance Monoid OptionalConfiguration where then cfg1 else cfg2 +-- | The Monoid instance essentially only provides the "empty +-- configuration." +instance Monoid OptionalConfiguration where + -- | An empty OptionalConfiguration. + mempty = OptionalConfiguration + Nothing + Nothing + (MxList []) + Nothing + Nothing + Nothing + Nothing + Nothing + mappend = (<>) + -- | Obtain an OptionalConfiguration from list-remote-forwardsrc in -- either the global configuration directory or the user's home