]> gitweb.michael.orlitzky.com - dead/harbl.git/blobdiff - harbl/src/Network/DNS/RBL/Weight.hs
Add Default and Ord instances for Weight.
[dead/harbl.git] / harbl / src / Network / DNS / RBL / Weight.hs
index e56bcd06496704e4c37e6c6ffaa26a08af9a763d..8447ab35cbd5de48411e68520ec9bbc16e440c74 100644 (file)
@@ -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.