Network arithmetic, finding the next host for the given
I think what you've missed is the Enum instance for the IPv4 datatype from iproute. Using methods from Enum and Bounded you can eliminate the use of Data.Bits in your code.

Because IPv4 is Enum, your toInt method is just fromEnum :: (Enum a) =&gt; a -&gt; Int. And similarly your fromInt is toEnum.

addressesInNetwork is largely the same logic, you just let someone else do all the work.

addressesInNetwork :: AddrRange IPv4 -&gt; [IPv4]
addressesInNetwork range = takeWhile (`isMatchedTo` range) [low..]
    where
        (low, _) = addrRangePair range


I would use addrRangePair instead of the addr field accessor for two reasons. First, addr doesn't show up in the Haddock documentation for Data.IP which is a bit confusing. Second, on the off-chance that the author of iproute begins hiding the constructors of AddrRange from export (which is very common practice in Haskell so that library authors can change implementations without breaking users' code) you'll be safe from breaking changes.

Knowing the Enum instance and available Data.IP functions, you can now write a clearer version of successor. Unfortunately we have to be a bit cautious of bounds, Enum throws an exception if you try to get the successor of maxBound, but it's not too bad.

successor :: AddrRange IPv4 -&gt; IPv4 -&gt; Maybe IPv4
successor range ip | ip == maxBound              = Nothing
                   | succ ip `isMatchedTo` range = Just $ succ ip
                   | otherwise                   = Nothing


Notice I changed the type signature of your function to take an AddrRange instead of a mask length. This is kind of a separation of concerns issue, successor doesn't care about the mask length, what matters is whether an IP falls within the range it defines. So net24 would be implemented as&mdash;

net24 :: IPv4 -&gt; Maybe IPv4
net24 ip = successor (makeAddrRange ip 24) ip


(That's kind of a strange name though, maybe successorMask24 instead?)