X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fharbl.git;a=blobdiff_plain;f=harbl-cli%2Fsrc%2FLists.hs;h=4870f895d3845bdf8811fd2b2af235b829daecd8;hp=8edb167e30685abbd37b777dde3506e19bda7243;hb=98b9d8768fe78d9948151e499ec52f7f616bd6e9;hpb=b55e5db2a68be5d69b970bbe4b5ad447881abd3d diff --git a/harbl-cli/src/Lists.hs b/harbl-cli/src/Lists.hs index 8edb167..4870f89 100644 --- a/harbl-cli/src/Lists.hs +++ b/harbl-cli/src/Lists.hs @@ -3,45 +3,33 @@ -- [String] if we had defined one in e.g. 'OptionalConfiguration'. -- {-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Lists ( Lists(..) ) where --- DC is needed only for the DCT.Configured instance of String. -import qualified Data.Configurator as DC() -import qualified Data.Configurator.Types as DCT ( - Configured, - Value( List ), - convert ) +import Data.Configurator () -- Needed for predefined instances. +import Data.Configurator.Types ( Configured(..) ) import Data.Data ( Data ) +import Data.Monoid ( Monoid ) import System.Console.CmdArgs.Default ( Default(..) ) import Data.Typeable ( Typeable ) +import Configurator ( convert_newtype_list ) + -- | A (wrapper around a) list of blacklists. -- newtype Lists = Lists { get_lists :: [String] } - deriving (Data, Show, Typeable) + deriving (Data, Eq, Monoid, Show, Typeable) -- | The default list of white/blacklists. It's empty. -- instance Default Lists where def = Lists [] -instance DCT.Configured Lists where +instance Configured Lists where -- | This allows us to read a 'Lists' 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 Lists constructor to - -- it. - convert (DCT.List xs) = - -- mapM gives us a Maybe [String] here. - fmap Lists (mapM convert_string xs) - where - convert_string :: DCT.Value -> Maybe String - convert_string = DCT.convert - - -- If we read anything other than a list of values out of the file, - -- fail. - convert _ = Nothing + -- config file: by default Configurator wouldn't know what to do. + convert = convert_newtype_list Lists