X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FUsernames.hs;h=e31b118405c908c1eab3e09b6fc54b43d3e18cae;hp=92e5c4376f77fc2416044941ee3457f0597727cc;hb=15fd6f764f88f79424d7caaba564e57df564b532;hpb=d7c6b5499c0969b6e488d9fc583f93bbb4e3d4c7 diff --git a/src/Usernames.hs b/src/Usernames.hs index 92e5c43..e31b118 100644 --- a/src/Usernames.hs +++ b/src/Usernames.hs @@ -11,20 +11,45 @@ where import qualified Data.Configurator as DC() import qualified Data.Configurator.Types as DCT import Data.Data ( Data ) -import System.Console.CmdArgs.Default ( Default(..) ) +import Data.Monoid ( Monoid(..) ) import Data.Typeable ( Typeable ) +import System.Console.CmdArgs.Default ( Default(..) ) +-- | Wrapper around a list of strings (usernames). +-- newtype Usernames = Usernames { get_usernames :: [String] } deriving (Data, Show, Typeable) instance Default Usernames where + -- | The default list of usernames is empty. + -- def = Usernames [] +-- | The 'Monoid' instance for 'Usernames' uses an +-- 'Monoid' instance for lists. +-- +instance Monoid Usernames where + -- | The \"empty\" 'Usernames' simply wraps an empty list. + mempty = Usernames [] + + -- | This mappend is a little funny; it always chooses the second + -- list if that list is nonempty. Otherwise, it chooses the + -- first. This is actually associative! + u1 `mappend` u2 + | null (get_usernames u2) = u1 + | otherwise = u2 + + instance DCT.Configured Usernames where + -- | This allows us to read a 'Usernames' object out of a + -- Configurator config file. By default Configurator wouldn't know + -- what to do, so we have to tell it that we expect a list, and if + -- that list has strings in it, we can apply the Usernames + -- constructor to it. convert (DCT.List xs) = fmap Usernames (mapM convert_string xs) where