From: Michael Orlitzky Date: Fri, 17 Jul 2015 05:18:17 +0000 (-0400) Subject: Add Default and Ord instances for Weight. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=6eb7fe0f53b0d8690a821cce9257b8b1a17fdaad;p=dead%2Fharbl.git Add Default and Ord instances for Weight. --- diff --git a/harbl.cabal b/harbl.cabal index a970d30..e59c437 100644 --- a/harbl.cabal +++ b/harbl.cabal @@ -17,6 +17,7 @@ library build-depends: base >= 4.6 && < 5, bytestring >= 0.9, + cmdargs >= 0.10.6, dns >= 2, iproute >= 1.4, parsec >= 3, @@ -80,6 +81,8 @@ executable harbl hs-source-dirs: harbl-cli/src + -- Other modules needed... + ghc-options: -Wall -fwarn-hi-shadowing diff --git a/harbl/src/Network/DNS/RBL/Weight.hs b/harbl/src/Network/DNS/RBL/Weight.hs index e56bcd0..8447ab3 100644 --- a/harbl/src/Network/DNS/RBL/Weight.hs +++ b/harbl/src/Network/DNS/RBL/Weight.hs @@ -15,6 +15,7 @@ module Network.DNS.RBL.Weight ( weight ) where +import System.Console.CmdArgs.Default ( Default(..) ) import Text.Parsec ( (<|>), char, @@ -47,7 +48,7 @@ import Network.DNS.RBL.Pretty ( Pretty(..) ) -- >>> sum [w1, w2, w3] -- Weight 4 -- -newtype Weight = Weight Int deriving (Eq, Num, Show) +newtype Weight = Weight Int deriving (Eq, Num, Ord, Show) -- | Pretty-print a 'Weight'. This just shows/prints the underlying 'Int'. @@ -61,6 +62,18 @@ instance Pretty Weight where pretty_show (Weight w) = show w +-- | Set a default value for the weight. We use the 'Default' class +-- from the CmdArgs class so that 'Weight's can be easily parsed on +-- the command-line. +-- +-- ==== _Examples_ +-- +-- >>> def :: Weight +-- Weight 1 +-- +instance Default Weight where def = 1 + + -- | Parse the weight multiplier off the end of an input 'Site'. This -- expects there to be a \"multiplier\" character (an asterisk) -- before the integral weight.