]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/IPv4Address.hs
hath.cabal: drop a word and a period from the synopsis
[hath.git] / src / IPv4Address.hs
index 4399b05f3ecb1728eca31be6eae5e833a23a3b5b..f9fd8c24e435ac9f2c5ba51d9665aa5243b94d47 100644 (file)
@@ -192,7 +192,7 @@ instance Enum IPv4Address where
   -- | Convert an 'Int' @x@ to an 'IPv4Address'. Each octet of @x@ is
   --   right-shifted by the appropriate number of bits, and the fractional
   --   part is dropped.
-  toEnum y =
+  toEnum signed_x =
     IPv4Address oct1 oct2 oct3 oct4
     where
       -- Convert the input Int to a Word32 before we proceed. On x86,
@@ -201,17 +201,17 @@ instance Enum IPv4Address where
       -- below doesn't work. The Word32 type is unsigned, so we do the
       -- math on that and then convert everything back to Int later on
       -- once we have four much-smaller non-negative numbers.
-      x = fromIntegral y :: Word32
+      x = fromIntegral signed_x :: Word32
 
       -- Chop off the higher octets. x1 = x `mod` 2^32, would be
       -- redundant.
-      x2 = x `mod` 2^(24 :: Integer)
-      x3 = x `mod` 2^(16 :: Integer)
-      x4 = (fromIntegral $ x `mod` 2^(8  :: Integer)) :: Int
+      x2 = x `mod` (2 ^ (24 :: Integer))
+      x3 = x `mod` (2 ^ (16 :: Integer))
+      x4 = (fromIntegral $ x `mod` (2 ^ (8 :: Integer))) :: Int
       -- Perform right-shifts. x4 doesn't need a shift.
-      shifted_x1 = (fromIntegral $ x `quot` 2^(24 :: Integer)) :: Int
-      shifted_x2 = (fromIntegral $ x2 `quot` 2^(16 :: Integer)) :: Int
-      shifted_x3 = fromIntegral $ x3 `quot` 2^(8 :: Integer) :: Int
+      shifted_x1 = (fromIntegral $ x  `quot` (2 ^ (24 :: Integer))) :: Int
+      shifted_x2 = (fromIntegral $ x2 `quot` (2 ^ (16 :: Integer))) :: Int
+      shifted_x3 = (fromIntegral $ x3 `quot` (2 ^ (8  :: Integer))) :: Int
       oct1 = toEnum shifted_x1 :: Octet
       oct2 = toEnum shifted_x2 :: Octet
       oct3 = toEnum shifted_x3 :: Octet
@@ -226,9 +226,9 @@ instance Enum IPv4Address where
       oct2 = fromEnum (octet2 addr)
       oct3 = fromEnum (octet3 addr)
       oct4 = fromEnum (octet4 addr)
-      shifted_oct1 = oct1 * 2^(24 :: Integer)
-      shifted_oct2 = oct2 * 2^(16 :: Integer)
-      shifted_oct3 = oct3 * 2^(8 :: Integer)
+      shifted_oct1 = oct1 * (2 ^ (24 :: Integer))
+      shifted_oct2 = oct2 * (2 ^ (16 :: Integer))
+      shifted_oct3 = oct3 * (2 ^ (8  :: Integer))
 
 -- | Given two addresses, find the number of the most significant bit
 --   where they differ. If the addresses are the same, return
@@ -386,7 +386,7 @@ prop_from_enum_to_enum_inverses_x64 =
   where
     prop :: (Small Int64) -> Property
     prop x =
-      0 <= x && x <= 2^(32 :: Integer) - 1 ==>
+      0 <= x && x <= (2 ^ (32 :: Integer)) - 1 ==>
         fromIntegral (fromEnum (toEnum (fromIntegral x) :: IPv4Address)) == x
 
 -- According to the QuickCheck documentation, we need the "Large"